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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_cache.vhdl] - Blame information for rev 133

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

Line No. Rev Author Line
1 114 ja_rd
--------------------------------------------------------------------------------
2
-- mips_cache.vhdl -- cache module
3
--
4
-- This module contains both MIPS caches (I-Cache and D-Cache) combined with
5
-- all the glue logic used to decode and interface external memories and
6
-- devices, both synchronous and asynchronous. 
7
-- Everything that goes into or comes from the CPU passes through this module.
8
--
9
-- The D-Cache is unimplemented in this version, and uses the logic from the
10
-- stub cache module.
11
--
12
-- Main cache parameters:
13
--
14
-- I-Cache: 256 4-word lines, direct mapped.
15
-- D-Cache: 256 4-word lines, direct mapped, write-through (UNIMPLEMENTED YET)
16
--
17
-- The cache works mostly like the R3000 caches, except for the following 
18
-- traits:
19
--
20
-- 1.- When bit CP0[12].17='0' (reset value) the cache is 'disabled'. In this 
21
-- state, ALL memory reads miss the cache and force a line refill -- even 
22
-- succesive reads from the same line will refill the entire line. This 
23
-- simplifies the cache logic a lot but slows uncached code a lot. Which means 
24
-- you should initialize the cache and enable it ASAP after reset. 
25
-- 
26
-- 2.- When bits CP0[12].17:16 = "01", the CPU can invalidate a cache line N
27
-- by writing word N to ANY address. The address will be executed as normal AND
28
-- the cache controller will invalidate I-Cache line N.
29
--
30
-- Note that the standard behavior for bits 17 and 16 of the SR is not
31
-- implemented at all -- no cache swapping, etc.
32
--
33
-- 3.- In this version, all areas of memory are cacheable, except those mapped 
34
-- as MT_IO_SYNC or MT_UNMAPPEd in mips_pkg. 
35
-- Since you can enable or disable the cache at will this difference doesn't 
36
-- seem too important.
37
-- There is a 'cacheable' flag in the t_range_attr record which is currently 
38
-- unused.
39
--
40
-- 4.- The tag is only 14 bits long, which means the memory map is severely
41
-- restricted in this version. See @note2.
42
--
43
-- This is not the standard MIPS way but is compatible enough and above all it
44
-- is simple.
45
--
46
--------------------------------------------------------------------------------
47
-- NOTES:
48
--
49
-- @note1: I-Cache initialization and tag format
50
--
51
-- In the tag table (code_tag_table), tags are stored together with a 'valid' 
52
-- bit (MSB), which is '0' for VALID tags.
53
-- When the CPU invalidates a line, it writes a '1' in the proper tag table 
54
-- entry together with the tag value.
55
-- When tags are matched, the valid bit is matched against 
56
--
57
--
58
-- @note2: I-Cache tags and cache mirroring
59
-- 
60
-- To save space in the I-Cache tag table, the tags are shorter than they 
61
-- should -- 14 bits instead of the 20 bits we would need to cover the
62
-- entire 32-bit address:
63
--
64
--             ___________ <-- These address bits are NOT in the tag
65
--            /           \
66
--  31 ..   27| 26 .. 21  |20 ..          12|11  ..        4|3:2|
67
--  +---------+-----------+-----------------+---------------+---+---+
68
--  | 5       |           | 9               | 8             | 2 |   |
69
--  +---------+-----------+-----------------+---------------+---+---+
70
--  ^                     ^                 ^               ^- LINE_INDEX_SIZE
71
--  5 bits                9 bits            LINE_NUMBER_SIZE
72
--
73
-- Since bits 26 downto 21 are not included in the tag, there will be a 
74
-- 'mirror' effect in the cache. We have split the memory space 
75
-- into 32 separate blocks of 1MB which is obviously not enough but will do
76
-- for the initial tests.
77
-- In subsequen versions of the cache, the tag size needs to be enlarged AND 
78
-- some of the top bits might be omitted when they're not needed to implement 
79
-- the default memory map (namely bit 30 which is always '0').
80
--
81
--
82
-- @note3: Possible bug in Quartus-II and workaround
83
--
84
-- I had to put a 'dummy' mux between the cache line store and the CPU in order 
85
-- to get rid of a quirk in Quartus-II synthseizer (V9.0 build 235).
86
-- If we omit this extra dummy layer of logic the synth will fail to infer the 
87
-- tag table as a BRAM and will use logic fabric instead, crippling performance.
88
-- The mux is otherwise useless and hits performance badly, but so far I haven't
89
-- found any other way to overcome this bug, not even with the helop of the  
90
-- Altera support forum.
91
--
92
--------------------------------------------------------------------------------
93
-- This module interfaces the CPU to the following:
94
--
95
--  1.- Internal 32-bit-wide BRAM for read only
96
--  2.- Internal 32-bit I/O bus
97
--  3.- External 16-bit or 8-bit wide static memory (SRAM or FLASH)
98
--  4.- External 16-bit wide SDRAM (NOT IMPLEMENTED YET)
99
--
100
-- The SRAM memory interface signals are meant to connect directly to FPGA pins
101
-- and all outputs are registered (tco should be minimal).
102
-- SRAM data inputs are NOT registered, though. They go through a couple muxes
103
-- before reaching the first register so watch out for tsetup.
104
--
105
-- This is a work in progress, based on the dummy cache module. 
106
--
107
--------------------------------------------------------------------------------
108
-- External FPGA signals
109
--
110
-- This module has signals meant to connect directly to FPGA pins: the SRAM
111
-- interface. They are either direct register outputs or at most with an
112
-- intervening 2-mux, in order to minimize the Tco (clock-to-output).
113
--
114
-- The Tco of these signals has to be accounted for in the real SRAM interface.
115
-- For example, under Quartus-2 and with a Cyclone-2 grade -7 device, the
116
-- worst Tco for the SRAM data pins is below 5 ns, enough to use a 10ns SRAM
117
-- with a 20 ns clock cycle.
118
-- Anyway, you need to take care of this yourself (synthesis constraints).
119
--
120
--------------------------------------------------------------------------------
121
-- Interface to CPU
122
--
123
-- 1.- All signals coming from the CPU are registered.
124
-- 2.- All CPU inputs come directly from a register, or at most have a 2-mux in
125
--     between.
126
--
127
-- This means this block will not degrade the timing performance of the system,
128
-- as long as its logic is shallower than the current bottleneck (the ALU).
129
--
130
--------------------------------------------------------------------------------
131
-- KNOWN PROBLEMS:
132
--
133
-- 1.- All parameters hardcoded -- generics are almost ignored.
134
--------------------------------------------------------------------------------
135
 
136
library ieee;
137
use ieee.std_logic_1164.all;
138
use ieee.std_logic_arith.all;
139
use ieee.std_logic_unsigned.all;
140
use work.mips_pkg.all;
141
 
142
 
143
entity mips_cache is
144
    generic (
145
        BRAM_ADDR_SIZE : integer    := 10;  -- BRAM address size
146
        SRAM_ADDR_SIZE : integer    := 17;  -- Static RAM/Flash address size
147
 
148
        -- these cache parameters are unused in this implementation, they're
149
        -- here for compatibility to the final cache module.
150
        LINE_SIZE : integer         := 4;   -- Line size in words
151
        CACHE_SIZE : integer        := 256  -- I- and D- cache size in lines
152
    );
153
    port(
154
        clk             : in std_logic;
155
        reset           : in std_logic;
156
 
157
        -- Interface to CPU core
158
        data_addr       : in std_logic_vector(31 downto 0);
159
        data_rd         : out std_logic_vector(31 downto 0);
160
        data_rd_vma     : in std_logic;
161
 
162
        code_rd_addr    : in std_logic_vector(31 downto 2);
163
        code_rd         : out std_logic_vector(31 downto 0);
164
        code_rd_vma     : in std_logic;
165
 
166
        byte_we         : in std_logic_vector(3 downto 0);
167
        data_wr         : in std_logic_vector(31 downto 0);
168
 
169
        mem_wait        : out std_logic;
170
        cache_enable    : in std_logic;
171
        ic_invalidate   : in std_logic;
172
 
173
        -- interface to FPGA i/o devices
174
        io_rd_data      : in std_logic_vector(31 downto 0);
175
        io_rd_addr      : out std_logic_vector(31 downto 2);
176
        io_wr_addr      : out std_logic_vector(31 downto 2);
177
        io_wr_data      : out std_logic_vector(31 downto 0);
178
        io_rd_vma       : out std_logic;
179
        io_byte_we      : out std_logic_vector(3 downto 0);
180
 
181
        -- interface to synchronous 32-bit-wide FPGA BRAM (possibly used as ROM)
182
        bram_rd_data    : in std_logic_vector(31 downto 0);
183
        bram_wr_data    : out std_logic_vector(31 downto 0);
184
        bram_rd_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
185
        bram_wr_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
186
        bram_byte_we    : out std_logic_vector(3 downto 0);
187
        bram_data_rd_vma: out std_logic;
188
 
189
        -- interface to asynchronous 16-bit-wide or 8-bit-wide static memory
190
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE-1 downto 0);
191
        sram_data_rd    : in std_logic_vector(15 downto 0);
192
        sram_data_wr    : out std_logic_vector(15 downto 0);
193
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
194
        sram_oe_n       : out std_logic
195
    );
196
end entity mips_cache;
197
 
198
 
199
architecture direct of mips_cache is
200
 
201
-- Address of line within line store
202
constant LINE_NUMBER_SIZE : integer := log2(CACHE_SIZE);
203
-- Address of word within line
204
constant LINE_INDEX_SIZE : integer  := log2(LINE_SIZE);
205
-- Address of word within line store
206
constant LINE_ADDR_SIZE : integer   := LINE_NUMBER_SIZE+LINE_INDEX_SIZE;
207
 
208
-- Code tag size, excluding valid bit
209
-- FIXME should be a generic
210
constant CODE_TAG_SIZE : integer    := 14;
211
-- Data tag size, excluding valid bit
212
-- FIXME should be a generic
213
constant DATA_TAG_SIZE : integer    := 14;
214
 
215
 
216
-- Wait state counter -- we're supporting static memory from 10 to >100 ns
217
-- (0 to 7 wait states with realistic clock rates).
218
subtype t_wait_state_counter is std_logic_vector(2 downto 0);
219
 
220
-- State machine ----------------------------------------------------
221
 
222
type t_cache_state is (
223
    idle,                       -- Cache is hitting, control machine idle
224
 
225
    -- Code refill --------------------------------------------------
226
    code_refill_bram_0,         -- pc in bram_rd_addr
227
    code_refill_bram_1,         -- op in bram_rd
228
    code_refill_bram_2,         -- op in code_rd
229
 
230
    code_refill_sram_0,         -- rd addr in SRAM addr bus (low hword)
231
    code_refill_sram_1,         -- rd addr in SRAM addr bus (high hword)
232
 
233
    code_refill_sram8_0,        -- rd addr in SRAM addr bus (byte 0)
234
    code_refill_sram8_1,        -- rd addr in SRAM addr bus (byte 1)
235
    code_refill_sram8_2,        -- rd addr in SRAM addr bus (byte 2)
236
    code_refill_sram8_3,        -- rd addr in SRAM addr bus (byte 3)
237
 
238
    code_crash,                 -- tried to run from i/o or something like that
239
 
240
    -- Data refill & write-through ----------------------------------
241
    data_refill_sram_0,         -- rd addr in SRAM addr bus (low hword)
242
    data_refill_sram_1,         -- rd addr in SRAM addr bus (high hword)
243
 
244
    data_refill_sram8_0,        -- rd addr in SRAM addr bus (byte 0)
245
    data_refill_sram8_1,        -- rd addr in SRAM addr bus (byte 1)
246
    data_refill_sram8_2,        -- rd addr in SRAM addr bus (byte 2)
247
    data_refill_sram8_3,        -- rd addr in SRAM addr bus (byte 3)
248
 
249
    data_refill_bram_0,         -- rd addr in bram_rd_addr
250
    data_refill_bram_1,         -- rd data in bram_rd_data
251
 
252
    data_read_io_0,             -- rd addr on io_rd_addr, io_vma active
253
    data_read_io_1,             -- rd data on io_rd_data
254
 
255
    data_write_io_0,            -- wr addr & data in io_wr_*, io_byte_we active
256
 
257
    data_writethrough_sram_0a,  -- wr addr & data in SRAM buses (low hword)
258
    data_writethrough_sram_0b,  -- WE asserted
259
    data_writethrough_sram_0c,  -- WE deasserted
260
    data_writethrough_sram_1a,  -- wr addr & data in SRAM buses (high hword)
261
    data_writethrough_sram_1b,  -- WE asserted
262
    data_writethrough_sram_1c,  -- WE deasserted
263
 
264
    data_ignore_write,          -- hook for raising error flag FIXME untested
265
    data_ignore_read,           -- hook for raising error flag FIXME untested
266
 
267
    -- Other states -------------------------------------------------
268
 
269
    --code_wait_for_dcache,       -- wait for D-cache to stop using the buses
270
    bug                         -- caught an error in the state machine
271
   );
272
 
273
-- Cache state machine state register & next state
274
signal ps, ns :             t_cache_state;
275
-- Wait state down-counter, formally part of the state machine register
276
signal ws_ctr :             t_wait_state_counter;
277
-- Wait states for memory being accessed
278
signal ws_value :           t_wait_state_counter;
279
-- Asserted to initialize the wait state counter
280
signal load_ws_ctr :        std_logic;
281
-- Asserted when the wait state counter has reached zero
282
signal ws_wait_done :       std_logic;
283
-- Refill word counters
284
signal code_refill_ctr :    integer range 0 to LINE_SIZE-1;
285
signal data_refill_ctr :    integer range 0 to LINE_SIZE-1;
286
 
287
-- CPU interface registers ------------------------------------------
288
signal data_rd_addr_reg :   t_pc;
289
signal data_wr_addr_reg :   t_pc;
290
signal code_rd_addr_reg :   t_pc;
291
 
292
signal data_wr_reg :        std_logic_vector(31 downto 0);
293
signal byte_we_reg :        std_logic_vector(3 downto 0);
294
 
295
-- SRAM interface ---------------------------------------------------
296
-- Stores first (high) HW read from SRAM
297
signal sram_rd_data_reg :   std_logic_vector(31 downto 8);
298
-- Data read from SRAM, valid in refill_1
299
signal sram_rd_data :       t_word;
300
 
301
 
302
-- I-cache ----------------------------------------------------------
303
 
304
subtype t_line_addr is std_logic_vector(LINE_NUMBER_SIZE-1 downto 0);
305
subtype t_word_addr is std_logic_vector(LINE_ADDR_SIZE-1 downto 0);
306
subtype t_code_tag is std_logic_vector(CODE_TAG_SIZE+1-1 downto 0);
307
type t_code_tag_table is array(CACHE_SIZE-1 downto 0) of t_code_tag;
308
type t_code_line_table is array((CACHE_SIZE*LINE_SIZE)-1 downto 0) of t_word;
309
 
310
-- Code tag table (stores line tags)
311
signal code_tag_table :     t_code_tag_table   := (others => "000000000000000");
312
-- Code line table  (stores lines)
313
signal code_line_table :    t_code_line_table  := (others => X"00000000");
314
 
315
-- Tag from code fetch address ('target' address, straight from CPU lines)
316
signal code_tag :           t_code_tag;
317
-- Registered code_tag, used matching after reading from code_tag_table
318
signal code_tag_reg :       t_code_tag;
319
-- Tag read from cache (will be matched against code_tag_reg)
320
signal code_cache_tag :     t_code_tag;
321
-- Code cache line address for read and write ports
322
signal code_line_addr :     t_line_addr;
323
-- Code cache word address (read from cache)
324
signal code_word_addr :     t_word_addr;
325
-- Code cache word address (write to cache in refills)
326
signal code_word_addr_wr :  t_word_addr;
327
 
328
-- This stuff is part of the workaround for @note3
329
attribute noprune: boolean;
330
attribute noprune of code_word_addr : signal is true;
331
attribute noprune of code_word_addr_wr : signal is true;
332
attribute noprune of ps : signal is true;
333
 
334
-- Word written into code cache
335
signal code_refill_data :   t_word;
336
-- Address the code refill data is fetched from
337
signal code_refill_addr :   t_pc;
338
 
339
-- code word read from cache
340
signal code_cache_rd :      t_word;
341
-- raised when code_cache_rd is not valid due to a cache miss
342
signal code_miss :          std_logic;
343
-- code_miss for accesses to CACHED areas with cache enabled
344
signal code_miss_cached : std_logic;
345
-- code_miss for accesses to UNCACHED areas OR with cache disabled
346
signal code_miss_uncached : std_logic;
347
-- '1' when the I-cache state machine stalls the pipeline (mem_wait)
348
signal code_wait :          std_logic;
349
 
350
-- D-cache -- most of this is unimplemented -------------------------
351
subtype t_data_tag is std_logic_vector(23 downto 2);
352
signal data_cache_tag :     t_data_tag;
353
signal data_cache_tag_store : t_data_tag;
354
signal data_cache_store :   t_word;
355
-- active when there's a write waiting to be done
356
signal write_pending :      std_logic;
357
-- active when there's a read waiting to be done
358
signal read_pending :       std_logic;
359
-- data word read from cache
360
signal data_cache_rd :      t_word;
361
-- '1' when data_cache_rd is not valid due to a cache miss
362
signal data_miss :          std_logic;
363
-- '1' when the D-cache state machine stalls the pipeline (mem_wait)
364
signal data_wait :          std_logic;
365
 
366
 
367
-- Address decoding -------------------------------------------------
368
 
369
-- Address slices used to decode
370
signal code_rd_addr_mask :  t_addr_decode;
371
signal data_rd_addr_mask :  t_addr_decode;
372
signal data_wr_addr_mask :  t_addr_decode;
373
 
374
-- Memory map area being accessed for each of the 3 buses:
375
signal code_rd_attr :       t_range_attr;
376
signal data_rd_attr :       t_range_attr;
377
signal data_wr_attr :       t_range_attr;
378
 
379
--------------------------------------------------------------------------------
380
begin
381
 
382
--------------------------------------------------------------------------------
383
-- Cache control state machine
384
 
385
cache_state_machine_reg:
386
process(clk)
387
begin
388
   if clk'event and clk='1' then
389
        if reset='1' then
390
            ps <= idle;
391
        else
392
            ps <= ns;
393
        end if;
394
    end if;
395
end process cache_state_machine_reg;
396
 
397
-- Unified control state machine for I-Cache and D-cache -----------------------
398
control_state_machine_transitions:
399
process(ps, code_rd_vma, code_miss,
400
        data_wr_attr.mem_type, data_rd_attr.mem_type, code_rd_attr.mem_type,
401
        ws_wait_done, code_refill_ctr,
402
        write_pending, read_pending)
403
begin
404
    case ps is
405
    when idle =>
406
        if code_miss='1' then
407
            case code_rd_attr.mem_type is
408
            when MT_BRAM        => ns <= code_refill_bram_0;
409
            when MT_SRAM_16B    => ns <= code_refill_sram_0;
410
            when MT_SRAM_8B     => ns <= code_refill_sram8_0;
411
            when others         => ns <= code_crash;
412
            end case;
413
 
414
        elsif write_pending='1' then
415
            case data_wr_attr.mem_type is
416
            when MT_BRAM        => ns <= data_ignore_write;
417
            when MT_SRAM_16B    => ns <= data_writethrough_sram_0a;
418
            when MT_IO_SYNC     => ns <= data_write_io_0;
419
            -- FIXME ignore write to undecoded area (clear pending flag)
420
            when others         => ns <= ps;
421
            end case;
422
 
423
        elsif read_pending='1' then
424
            case data_rd_attr.mem_type is
425
            when MT_BRAM        => ns <= data_refill_bram_0;
426
            when MT_SRAM_16B    => ns <= data_refill_sram_0;
427
            when MT_SRAM_8B     => ns <= data_refill_sram8_0;
428
            when MT_IO_SYNC     => ns <= data_read_io_0;
429
            -- FIXME ignore read from undecoded area (clear pending flag)
430
            when others         => ns <= data_ignore_read;
431
            end case;
432
 
433
        else
434
            ns <= ps;
435
        end if;
436
 
437
 
438
    -- Code refill states -------------------------------------------
439
 
440
    when code_refill_bram_0 =>
441
        ns <= code_refill_bram_1;
442
 
443
    when code_refill_bram_1 =>
444
        ns <= code_refill_bram_2;
445
 
446
    when code_refill_bram_2 =>
447
        if code_refill_ctr/=0 then
448
            -- Still not finished refilling line, go for next word
449
            ns <= code_refill_bram_0;
450
        else
451
            -- If there's a data operation pending, do it now
452
            if write_pending='1' then
453
                case data_wr_attr.mem_type is
454
                when MT_BRAM        => ns <= data_ignore_write;
455
                when MT_SRAM_16B    => ns <= data_writethrough_sram_0a;
456
                when MT_IO_SYNC     => ns <= data_write_io_0;
457
                -- FIXME ignore write to undecoded area (clear pending flag)
458
                when others         => ns <= ps;
459
                end case;
460
 
461
            elsif read_pending='1' then
462
                case data_rd_attr.mem_type is
463
                when MT_BRAM        => ns <= data_refill_bram_0;
464
                when MT_SRAM_16B    => ns <= data_refill_sram_0;
465
                when MT_SRAM_8B     => ns <= data_refill_sram8_0;
466
                when MT_IO_SYNC     => ns <= data_read_io_0;
467
                -- FIXME ignore read from undecoded area (clear pending flag)
468
                when others         => ns <= data_ignore_read;
469
                end case;
470
 
471
            else
472
                ns <= idle;
473
            end if;
474
        end if;
475
 
476
    when code_refill_sram_0 =>
477
        if ws_wait_done='1' then
478
            ns <= code_refill_sram_1;
479
        else
480
            ns <= ps;
481
        end if;
482
 
483
    when code_refill_sram_1 =>
484
        if code_refill_ctr/=0 and ws_wait_done='1' then
485
            -- Still not finished refilling line, go for next word
486
            ns <= code_refill_sram_0;
487
        else
488
            if ws_wait_done='1' then
489
                -- If there's a data operation pending, do it now
490
                if write_pending='1' then
491
                    case data_wr_attr.mem_type is
492
                    when MT_BRAM        => ns <= data_ignore_write;
493
                    when MT_SRAM_16B    => ns <= data_writethrough_sram_0a;
494
                    when MT_IO_SYNC     => ns <= data_write_io_0;
495
                    -- FIXME ignore write to undecoded area (clear pending flag)
496
                    when others         => ns <= ps;
497
                    end case;
498
 
499
                elsif read_pending='1' then
500
                    case data_rd_attr.mem_type is
501
                    when MT_BRAM        => ns <= data_refill_bram_0;
502
                    when MT_SRAM_16B    => ns <= data_refill_sram_0;
503
                    when MT_SRAM_8B     => ns <= data_refill_sram8_0;
504
                    when MT_IO_SYNC     => ns <= data_read_io_0;
505
                    -- FIXME ignore read from undecoded area (clear pending flag)
506
                    when others         => ns <= data_ignore_read;
507
                    end case;
508
 
509
                else
510
                    ns <= idle;
511
                end if;
512
            else
513
                ns <= ps;
514
            end if;
515
        end if;
516
 
517
    when code_refill_sram8_0 =>
518
        if ws_wait_done='1' then
519
            ns <= code_refill_sram8_1;
520
        else
521
            ns <= ps;
522
        end if;
523
 
524
    when code_refill_sram8_1 =>
525
        if ws_wait_done='1' then
526
            ns <= code_refill_sram8_2;
527
        else
528
            ns <= ps;
529
        end if;
530
 
531
    when code_refill_sram8_2 =>
532
        if ws_wait_done='1' then
533
            ns <= code_refill_sram8_3;
534
        else
535
            ns <= ps;
536
        end if;
537
 
538
    when code_refill_sram8_3 =>
539
        if code_refill_ctr/=0 and ws_wait_done='1' then
540
            -- Still not finished refilling line, go for next word
541
            ns <= code_refill_sram8_0;
542
        else
543
            if ws_wait_done='1' then
544
                -- If there's a data operation pending, do it now
545
                if write_pending='1' then
546
                    case data_wr_attr.mem_type is
547
                    when MT_BRAM        => ns <= data_ignore_write;
548
                    when MT_SRAM_16B    => ns <= data_writethrough_sram_0a;
549
                    when MT_IO_SYNC     => ns <= data_write_io_0;
550
                    -- FIXME ignore write to undecoded area (clear pending flag)
551
                    when others         => ns <= data_ignore_write;
552
                    end case;
553
 
554
                elsif read_pending='1' then
555
                    case data_rd_attr.mem_type is
556
                    when MT_BRAM        => ns <= data_refill_bram_0;
557
                    when MT_SRAM_16B    => ns <= data_refill_sram_0;
558
                    when MT_SRAM_8B     => ns <= data_refill_sram8_0;
559
                    when MT_IO_SYNC     => ns <= data_read_io_0;
560
                    -- FIXME ignore read from undecoded area (clear pending flag)
561
                    when others         => ns <= data_ignore_read;
562
                    end case;
563
 
564
                else
565
                    ns <= idle;
566
                end if;
567
            else
568
                ns <= ps;
569
            end if;
570
        end if;
571
 
572
    -- Data refill & write-through states ---------------------------
573
 
574
    when data_write_io_0 =>
575
        ns <= idle;
576
 
577
    when data_read_io_0 =>
578
        ns <= data_read_io_1;
579
 
580
    when data_read_io_1 =>
581
        ns <= idle;
582
 
583
    when data_refill_sram8_0 =>
584
        if ws_wait_done='1' then
585
            ns <= data_refill_sram8_1;
586
        else
587
            ns <= ps;
588
        end if;
589
 
590
    when data_refill_sram8_1 =>
591
        if ws_wait_done='1' then
592
            ns <= data_refill_sram8_2;
593
        else
594
            ns <= ps;
595
        end if;
596
 
597
    when data_refill_sram8_2 =>
598
        if ws_wait_done='1' then
599
            ns <= data_refill_sram8_3;
600
        else
601
            ns <= ps;
602
        end if;
603
 
604
    when data_refill_sram8_3 =>
605
        if ws_wait_done='1' then
606
            ns <= idle;
607
        else
608
            ns <= ps;
609
        end if;
610
 
611
    when data_refill_sram_0 =>
612
        if ws_wait_done='1' then
613
            ns <= data_refill_sram_1;
614
        else
615
            ns <= ps;
616
        end if;
617
 
618
    when data_refill_sram_1 =>
619
        if ws_wait_done='1' then
620
            ns <= idle;
621
        else
622
            ns <= ps;
623
        end if;
624
 
625
    when data_refill_bram_0 =>
626
        ns <= data_refill_bram_1;
627
 
628
    when data_refill_bram_1 =>
629
        ns <= idle;
630
 
631
    when data_writethrough_sram_0a =>
632
        ns <= data_writethrough_sram_0b;
633
 
634
    when data_writethrough_sram_0b =>
635
        if ws_wait_done='1' then
636
            ns <= data_writethrough_sram_0c;
637
        else
638
            ns <= ps;
639
        end if;
640
 
641
    when data_writethrough_sram_0c =>
642
        ns <= data_writethrough_sram_1a;
643
 
644
    when data_writethrough_sram_1a =>
645
        ns <= data_writethrough_sram_1b;
646
 
647
    when data_writethrough_sram_1b =>
648
        if ws_wait_done='1' then
649
            ns <= data_writethrough_sram_1c;
650
        else
651
            ns <= ps;
652
        end if;
653
 
654
    when data_writethrough_sram_1c =>
655
        if read_pending='1' then
656
            case data_rd_attr.mem_type is
657
            when MT_BRAM        => ns <= data_refill_bram_0;
658
            when MT_SRAM_16B    => ns <= data_refill_sram_0;
659
            when MT_SRAM_8B     => ns <= data_refill_sram8_0;
660
            when MT_IO_SYNC     => ns <= data_read_io_0;
661
            -- FIXME ignore read from undecoded area (clear pending flag)
662
            when others         => ns <= data_ignore_read;
663
            end case;
664
        else
665
            ns <= idle;
666
        end if;
667
 
668
    when data_ignore_write =>
669
        ns <= idle;
670
 
671
    when data_ignore_read =>
672
        ns <= idle;
673
 
674
    -- Exception states (something went wrong) ----------------------
675
 
676
    when code_crash =>
677
        -- Attempted to fetch from i/o area. This is a software bug, probably,
678
        -- and should trigger a trap. We have 1 cycle to do something about it.
679
        -- FIXME do something about wrong fetch: trap, etc.
680
        -- After this cycle, back to normal.
681
        ns <= idle;
682
 
683
    when bug =>
684
        -- Something weird happened, we have 1 cycle to do something like raise
685
        -- an error flag, etc. After 1 cycle, back to normal.
686
        -- FIXME raise trap or flag or something
687
        ns <= idle;
688
 
689
    when others =>
690
        -- We should never arrive here. If we do we handle it in state bug.
691
        ns <= bug;
692
    end case;
693
end process control_state_machine_transitions;
694
 
695
 
696
--------------------------------------------------------------------------------
697
-- Wait state logic
698
 
699
-- load wait state counter when we're entering the state we will wait on
700
load_ws_ctr <= '1' when
701
    (ns=code_refill_sram_0  and ps/=code_refill_sram_0) or
702
    (ns=code_refill_sram_1  and ps/=code_refill_sram_1) or
703
    (ns=code_refill_sram8_0 and ps/=code_refill_sram8_0) or
704
    (ns=code_refill_sram8_1 and ps/=code_refill_sram8_1) or
705
    (ns=code_refill_sram8_2 and ps/=code_refill_sram8_2) or
706
    (ns=code_refill_sram8_3 and ps/=code_refill_sram8_3) or
707
    (ns=data_refill_sram_0  and ps/=data_refill_sram_0) or
708
    (ns=data_refill_sram_1  and ps/=data_refill_sram_1) or
709
    (ns=data_refill_sram8_0 and ps/=data_refill_sram8_0) or
710
    (ns=data_refill_sram8_1 and ps/=data_refill_sram8_1) or
711
    (ns=data_refill_sram8_2 and ps/=data_refill_sram8_2) or
712
    (ns=data_refill_sram8_3 and ps/=data_refill_sram8_3) or
713
    (ns=data_writethrough_sram_0a) or
714
    (ns=data_writethrough_sram_1a)
715
    else '0';
716
 
717
 
718
-- select the wait state counter value as that of read address or write address
719
with ns select ws_value <=
720
    data_rd_attr.wait_states    when data_refill_sram_0,
721
    data_rd_attr.wait_states    when data_refill_sram_1,
722
    data_rd_attr.wait_states    when data_refill_sram8_0,
723
    data_rd_attr.wait_states    when data_refill_sram8_1,
724
    data_rd_attr.wait_states    when data_refill_sram8_2,
725
    data_rd_attr.wait_states    when data_refill_sram8_3,
726
    data_wr_attr.wait_states    when data_writethrough_sram_0a,
727
    data_wr_attr.wait_states    when data_writethrough_sram_1a,
728
    code_rd_attr.wait_states    when code_refill_sram_0,
729
    code_rd_attr.wait_states    when code_refill_sram_1,
730
    code_rd_attr.wait_states    when code_refill_sram8_0,
731
    code_rd_attr.wait_states    when code_refill_sram8_1,
732
    code_rd_attr.wait_states    when code_refill_sram8_2,
733
    code_rd_attr.wait_states    when code_refill_sram8_3,
734
    data_wr_attr.wait_states    when others;
735
 
736
 
737
wait_state_counter_reg:
738
process(clk)
739
begin
740
    if clk'event and clk='1' then
741
        if reset='1' then
742
            ws_ctr <= (others => '0');
743
        else
744
            if load_ws_ctr='1' then
745
                ws_ctr <= ws_value;
746
            elsif ws_wait_done='0' then
747
                ws_ctr <= ws_ctr - 1;
748
            end if;
749
        end if;
750
    end if;
751
end process wait_state_counter_reg;
752
 
753
ws_wait_done <= '1' when ws_ctr="000" else '0';
754
 
755
--------------------------------------------------------------------------------
756
-- Refill word counters
757
 
758
code_refill_word_counter:
759
process(clk)
760
begin
761
    if clk'event and clk='1' then
762
        if reset='1' or (code_miss='1' and ps=idle) then
763
            code_refill_ctr <= LINE_SIZE-1;
764
        else
765
            if (ps=code_refill_bram_2 or
766
               ps=code_refill_sram_1 or
767
               ps=code_refill_sram8_3) and
768
               ws_wait_done='1'  and
769
               code_refill_ctr/=0 then
770
            code_refill_ctr <= code_refill_ctr-1;
771
            end if;
772
        end if;
773
    end if;
774
end process code_refill_word_counter;
775
 
776
--------------------------------------------------------------------------------
777
-- CPU interface registers and address decoding --------------------------------
778
 
779
 
780
-- Everything coming and going to the CPU is registered, so that the CPU has
781
-- some timing marging. These are those registers.
782
-- Besides, we have here a couple of read/write pending flags used to properly
783
-- sequence the cache accesses (first fetch, then any pending r/w).
784
cpu_data_interface_registers:
785
process(clk)
786
begin
787
    if clk'event and clk='1' then
788
        if reset='1' then
789
            write_pending <= '0';
790
            read_pending <= '0';
791
            byte_we_reg <= "0000";
792
        else
793
            -- Raise 'read_pending' at 1st cycle of a data read, clear it when
794
            -- the read (and/or refill) operation has been done.
795
            -- data_rd_addr_reg always has the addr of any pending read
796
            if data_rd_vma='1' then
797
                read_pending <= '1';
798
                data_rd_addr_reg <= data_addr(31 downto 2);
799
            elsif ps=data_refill_sram_1 or
800
                  ps=data_refill_sram8_3 or
801
                  ps=data_refill_bram_1 or
802
                  ps=data_read_io_0 or
803
                  ps=data_ignore_read then
804
                read_pending <= '0';
805
            end if;
806
 
807
            -- Raise 'write_pending' at the 1st cycle of a write, clear it when
808
            -- the write (writethrough actually) operation has been done.
809
            -- data_wr_addr_reg always has the addr of any pending write
810
            if byte_we/="0000" and ps=idle then
811
                byte_we_reg <= byte_we;
812
                data_wr_reg <= data_wr;
813
                data_wr_addr_reg <= data_addr(31 downto 2);
814
                write_pending <= '1';
815
            elsif ps=data_writethrough_sram_1b or
816
                  ps=data_write_io_0 or
817
                  ps=data_ignore_write then
818
                write_pending <= '0';
819
                byte_we_reg <= "0000";
820
            end if;
821
 
822
        end if;
823
    end if;
824
end process cpu_data_interface_registers;
825
 
826
cpu_code_interface_registers:
827
process(clk)
828
begin
829
    if clk'event and clk='1' then
830
        -- Register code fetch addresses only when they are valid; so that
831
        -- code_rd_addr_reg always holds the last fetch address.
832
        if code_rd_vma='1' then
833
            code_rd_addr_reg <= code_rd_addr;
834
        end if;
835
    end if;
836
end process cpu_code_interface_registers;
837
 
838
-- The code refill address is that of the current code line, with the running
839
-- refill counter appended: we will read all the words from the line in sequence
840
-- (in REVERSE sequence, actually, see below).
841
code_refill_addr <=
842
    code_rd_addr_reg(code_rd_addr_reg'high downto 4) &
843
    conv_std_logic_vector(code_refill_ctr,LINE_INDEX_SIZE);
844
 
845
 
846
-- Address decoding ------------------------------------------------------------
847
 
848
-- Decoding is done on the high bits of the address only, there'll be mirroring.
849
-- Write to areas not explicitly decoded will be silently ignored. Reads will
850
-- get undefined data.
851
 
852
code_rd_addr_mask <= code_rd_addr_reg(31 downto t_addr_decode'low);
853
data_rd_addr_mask <= data_rd_addr_reg(31 downto t_addr_decode'low);
854
data_wr_addr_mask <= data_wr_addr_reg(31 downto t_addr_decode'low);
855
 
856
 
857
code_rd_attr <= decode_addr(code_rd_addr_mask);
858
data_rd_attr <= decode_addr(data_rd_addr_mask);
859
data_wr_attr <= decode_addr(data_wr_addr_mask);
860
 
861
 
862
--------------------------------------------------------------------------------
863
-- BRAM interface (BRAM is FPGA Block RAM)
864
 
865
-- BRAM address can come from code or data buses, we support code execution
866
-- and data r/w from BRAM.
867
-- (note both inputs to this mux are register outputs)
868
bram_rd_addr <=
869
    data_rd_addr_reg(bram_rd_addr'high downto 2)
870
        when ps=data_refill_bram_0 else
871
    code_refill_addr(bram_rd_addr'high downto 2) ;
872
 
873
bram_data_rd_vma <= '1' when ps=data_refill_bram_1 else '0';
874
 
875
 
876
--------------------------------------------------------------------------------
877
--------------------------------------------------------------------------------
878
-- Code cache
879
 
880
-- Most of the code cache is provisional, though it has already been tried on
881
-- hardware.
882
 
883
-- CPU is wired directly to cache output, no muxes -- or at least is SHOULD. 
884
-- Due to an apparent bug in Quartus-2 (V9.0 build 235), if we omit this extra
885
-- dummy layer of logic the synth will fail to infer the tag table as a BRAM.
886
-- (@note3)
887
code_rd <= code_cache_rd when reset='0' else X"00000000";
888
 
889
-- Register here the requested code tag so we can compare it to the tag in the
890
-- cache store. Note we register and match the 'line valid' bit together with
891
-- the rest of the tag.
892
code_tag_register:
893
process(clk)
894
begin
895
    if clk'event and clk='1' then
896
        -- Together with the tag value, we register the valid bit against which 
897
        -- we will match after reading the tag table.
898
        -- The valid bit will be '0' for normal accesses or '1' when the cache 
899
        -- is disabled OR we're invalidating lines. This ensures that the cache
900
        -- will miss in those cases.
901
        code_tag_reg <= (ic_invalidate or (not cache_enable)) &
902
                        code_tag(code_tag'high-1 downto 0);
903
    end if;
904
end process code_tag_register;
905
 
906
-- The I-Cache misses when the tag in the cache is not the tag we want or 
907
-- it is not valid.
908
code_miss_cached <= '1' when (code_tag_reg /= code_cache_tag) else '0';
909
 
910
-- When cache is disabled, ALL code fetches will miss
911
uncached_code_miss_logic:
912
process(clk)
913
begin
914
    if clk'event and clk='1' then
915
        if reset='1' then
916
            code_miss_uncached <= '0';
917
        else
918
            code_miss_uncached <= code_rd_vma; -- always miss
919
        end if;
920
    end if;
921
end process uncached_code_miss_logic;
922
 
923
-- Select the proper code_miss signal
924
code_miss <= code_miss_uncached when cache_enable='0' else code_miss_cached;
925
 
926
 
927
-- Code line address used for both read and write into the table
928
code_line_addr <=
929
    -- when the CPU wants to invalidate I-Cache lines, the addr comes from the
930
    -- data bus (see @note1)
931
    data_wr(7 downto 0) when byte_we(3)='1' and ic_invalidate='1'
932
    -- otherwise the addr comes from the code address as usual
933
    else code_rd_addr(11 downto 4);
934
 
935
code_word_addr <= code_rd_addr(11 downto 2);
936
code_word_addr_wr <= code_line_addr & conv_std_logic_vector(code_refill_ctr,LINE_INDEX_SIZE);
937
-- NOTE: the tag will be marked as INVALID ('1') when the CPU is invalidating 
938
-- code lines (@note1)
939
code_tag <=
940
    (ic_invalidate) &
941
    code_rd_addr(31 downto 27) &
942
    code_rd_addr(11+CODE_TAG_SIZE-5 downto 11+1);
943
 
944
 
945
code_tag_memory:
946
process(clk)
947
begin
948
    if clk'event and clk='1' then
949
        if ps=code_refill_bram_1 or ps=code_refill_sram8_3 or ps=code_refill_sram_1 then
950
            code_tag_table(conv_integer(code_line_addr)) <= code_tag;
951
        end if;
952
 
953
        code_cache_tag <= code_tag_table(conv_integer(code_line_addr));
954
    end if;
955
end process code_tag_memory;
956
 
957
 
958
code_line_memory:
959
process(clk)
960
begin
961
    if clk'event and clk='1' then
962
        if ps=code_refill_bram_1 or ps=code_refill_sram8_3 or ps=code_refill_sram_1 then
963
            code_line_table(conv_integer(code_word_addr_wr)) <= code_refill_data;
964
        end if;
965
 
966
        code_cache_rd <= code_line_table(conv_integer(code_word_addr));
967
    end if;
968
end process code_line_memory;
969
 
970
-- Code can only come from BRAM or SRAM (including 16- and 8- bit interfaces)
971
with ps select code_refill_data <=
972
    bram_rd_data    when code_refill_bram_1,
973
    sram_rd_data    when others;
974
 
975
 
976
--------------------------------------------------------------------------------
977
--------------------------------------------------------------------------------
978
-- Data cache (unimplemented -- uses stub cache logic)
979
 
980
-- CPU data input mux: direct cache output OR uncached io input
981
with ps select data_rd <=
982
    io_rd_data      when data_read_io_1,
983
    data_cache_rd   when others;
984
 
985
-- All the tag match logic is unfinished and will be simplified away in synth.
986
-- The 'cache' is really a single register.
987
data_cache_rd <= data_cache_store;
988
data_cache_tag <= data_cache_tag_store;
989
 
990
data_cache_memory:
991
process(clk)
992
begin
993
    if clk'event and clk='1' then
994
        if reset='1' then
995
            -- in the real hardware the tag store can't be reset and it's up
996
            -- to the SW to initialize the cache.
997
            data_cache_tag_store <= (others => '0');
998
            data_cache_store <= (others => '0');
999
        else
1000
            -- Refill data cache if necessary
1001
            if ps=data_refill_sram_1 or ps=data_refill_sram8_3 then
1002
                data_cache_tag_store <=
1003
                    "01" & data_rd_addr_reg(t_data_tag'high-2 downto t_data_tag'low);
1004
                data_cache_store <= sram_rd_data;
1005
            elsif ps=data_refill_bram_1 then
1006
                data_cache_tag_store <=
1007
                    "01" & data_rd_addr_reg(t_data_tag'high-2 downto t_data_tag'low);
1008
                data_cache_store <= bram_rd_data;
1009
            end if;
1010
        end if;
1011
    end if;
1012
end process data_cache_memory;
1013
 
1014
 
1015
--------------------------------------------------------------------------------
1016
--------------------------------------------------------------------------------
1017
-- SRAM interface
1018
 
1019
-- Note this signals are meant to be connected directly to FPGA pins (and then
1020
-- to a SRAM, of course). They are the only signals whose tco we care about.
1021
 
1022
-- FIXME should add a SRAM CE\ signal
1023
 
1024
-- SRAM address bus (except for LSB) comes from cpu code or data addr registers
1025
 
1026
sram_address(sram_address'high downto 2) <=
1027
    data_rd_addr_reg(sram_address'high downto 2)
1028
        when   (ps=data_refill_sram_0  or ps=data_refill_sram_1 or
1029
                ps=data_refill_sram8_0 or ps=data_refill_sram8_1 or
1030
                ps=data_refill_sram8_2 or ps=data_refill_sram8_3) else
1031
    code_refill_addr(sram_address'high downto 2)
1032
        when   (ps=code_refill_sram_0  or ps=code_refill_sram_1 or
1033
                ps=code_refill_sram8_0 or ps=code_refill_sram8_1 or
1034
                ps=code_refill_sram8_2 or ps=code_refill_sram8_3) else
1035
    data_wr_addr_reg(sram_address'high downto 2);
1036
 
1037
-- SRAM addr bus LSB depends on the D-cache state because we read/write the
1038
-- halfwords sequentially in successive cycles.
1039
sram_address(1) <=
1040
    '0'     when   (ps=data_writethrough_sram_0a or
1041
                    ps=data_writethrough_sram_0b or
1042
                    ps=data_writethrough_sram_0c or
1043
                    ps=data_refill_sram8_0 or
1044
                    ps=data_refill_sram8_1 or
1045
                    ps=data_refill_sram_0 or
1046
                    ps=code_refill_sram8_0 or
1047
                    ps=code_refill_sram8_1 or
1048
                    ps=code_refill_sram_0) else
1049
    '1'     when   (ps=data_writethrough_sram_1a or
1050
                    ps=data_writethrough_sram_1b or
1051
                    ps=data_writethrough_sram_1c or
1052
                    ps=data_refill_sram8_2 or
1053
                    ps=data_refill_sram8_3 or
1054
                    ps=data_refill_sram_1 or
1055
                    ps=code_refill_sram8_2 or
1056
                    ps=code_refill_sram8_3 or
1057
                    ps=code_refill_sram_1)
1058
    else '0';
1059
 
1060
-- The lowest addr bit will only be used when accessing byte-wide memory, and
1061
-- even when we're reading word-aligned code (because we need to read the four 
1062
-- bytes one by one).
1063
sram_address(0) <=
1064
    '0'     when (ps=data_refill_sram8_0 or ps=data_refill_sram8_2 or
1065
                  ps=code_refill_sram8_0 or ps=code_refill_sram8_2) else
1066
    '1';
1067
 
1068
 
1069
-- SRAM databus (when used for output) comes from either hword of the data
1070
-- write register.
1071
with ps select sram_data_wr <=
1072
    data_wr_reg(31 downto 16)   when data_writethrough_sram_0a,
1073
    data_wr_reg(31 downto 16)   when data_writethrough_sram_0b,
1074
    data_wr_reg(31 downto 16)   when data_writethrough_sram_0c,
1075
    data_wr_reg(15 downto  0)   when data_writethrough_sram_1a,
1076
    data_wr_reg(15 downto  0)   when data_writethrough_sram_1b,
1077
    data_wr_reg(15 downto  0)   when data_writethrough_sram_1c,
1078
    (others => 'Z')             when others;
1079
 
1080
-- The byte_we is split in two similarly.
1081
with ps select sram_byte_we_n <=
1082
    not byte_we_reg(3 downto 2) when data_writethrough_sram_0b,
1083
    not byte_we_reg(1 downto 0) when data_writethrough_sram_1b,
1084
    "11"                        when others;
1085
 
1086
-- SRAM OE\ is only asserted low for read cycles
1087
sram_oe_n <=
1088
    '0' when   (ps=data_refill_sram_0  or ps=data_refill_sram_1 or
1089
                ps=data_refill_sram8_0 or ps=data_refill_sram8_1 or
1090
                ps=data_refill_sram8_2 or ps=data_refill_sram8_3 or
1091
                ps=code_refill_sram_0  or ps=code_refill_sram_1 or
1092
                ps=code_refill_sram8_0 or ps=code_refill_sram8_1 or
1093
                ps=code_refill_sram8_2 or ps=code_refill_sram8_3) else
1094
    '1';
1095
 
1096
-- When reading from the SRAM, read word comes from read hword register and
1097
-- SRAM bus (read register is loaded in previous cycle).
1098
sram_rd_data <=
1099
    sram_rd_data_reg & sram_data_rd(7 downto 0)
1100
            when ps=data_refill_sram8_3 or ps=code_refill_sram8_3 else
1101
    sram_rd_data_reg(31 downto 16) & sram_data_rd;
1102
 
1103
sram_input_halfword_register:
1104
process(clk)
1105
begin
1106
    if clk'event and clk='1' then
1107
        if ps=data_refill_sram_0 or ps=code_refill_sram_0 then
1108
            sram_rd_data_reg(31 downto 16) <= sram_data_rd;
1109
        elsif ps=data_refill_sram8_0 or ps=code_refill_sram8_0 then
1110
            sram_rd_data_reg(31 downto 24) <= sram_data_rd(7 downto 0);
1111
        elsif ps=data_refill_sram8_1 or ps=code_refill_sram8_1 then
1112
            sram_rd_data_reg(23 downto 16) <= sram_data_rd(7 downto 0);
1113
        elsif ps=data_refill_sram8_2 or ps=code_refill_sram8_2 then
1114
            sram_rd_data_reg(15 downto  8) <= sram_data_rd(7 downto 0);
1115
        end if;
1116
    end if;
1117
end process sram_input_halfword_register;
1118
 
1119
 
1120
--------------------------------------------------------------------------------
1121
-- I/O interface -- IO is assumed to behave like synchronous memory
1122
 
1123
io_byte_we <= byte_we_reg when ps=data_write_io_0 else "0000";
1124
io_rd_addr <= data_rd_addr_reg;
1125
io_wr_addr <= data_wr_addr_reg;
1126
io_wr_data <= data_wr_reg;
1127
io_rd_vma <= '1' when ps=data_read_io_0 else '0';
1128
 
1129
 
1130
--------------------------------------------------------------------------------
1131
-- CPU stall control
1132
 
1133
-- FIXME data_miss should be raised only on the cycle a data miss is detected,
1134
-- otherwise it overlaps data_wait
1135
data_miss <= read_pending; -- FIXME stub; will change with real D-Cache
1136
 
1137
-- Stall the CPU when either state machine needs it
1138
mem_wait <=
1139
    (code_wait or data_wait or  -- code or data refill in course
1140
     code_miss or data_miss     -- code or data miss
1141
     ) and not reset; -- FIXME stub
1142
 
1143
-- Assert code_wait until the cycle where the CPU has valid code word on its
1144
-- code bus
1145
with ps select code_wait <=
1146
    '1' when code_refill_bram_0,
1147
    '1' when code_refill_bram_1,
1148
    '1' when code_refill_bram_2,
1149
    '1' when code_refill_sram_0,
1150
    '1' when code_refill_sram_1,
1151
    '1' when code_refill_sram8_0,
1152
    '1' when code_refill_sram8_1,
1153
    '1' when code_refill_sram8_2,
1154
    '1' when code_refill_sram8_3,
1155
    '0' when others;
1156
 
1157
-- Assert data_wait until the cycle where the CPU has valid data word on its
1158
-- code bus AND no other operations are ongoing that may use the external buses.
1159
with ps select data_wait <=
1160
    '1' when data_writethrough_sram_0a,
1161
    '1' when data_writethrough_sram_0b,
1162
    '1' when data_writethrough_sram_0c,
1163
    '1' when data_writethrough_sram_1a,
1164
    '1' when data_writethrough_sram_1b,
1165
    '1' when data_writethrough_sram_1c,
1166
    '1' when data_refill_sram_0,
1167
    '1' when data_refill_sram_1,
1168
    '1' when data_refill_sram8_0,
1169
    '1' when data_refill_sram8_1,
1170
    '1' when data_refill_sram8_2,
1171
    '1' when data_refill_sram8_3,
1172
    '1' when data_refill_bram_0,
1173
    '1' when data_refill_bram_1,
1174
    '1' when data_read_io_0,
1175
    '0' when others;
1176
 
1177
end architecture direct;

powered by: WebSVN 2.1.0

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