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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_cache_stub.vhdl] - Blame information for rev 58

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

Line No. Rev Author Line
1 42 ja_rd
--------------------------------------------------------------------------------
2 46 ja_rd
-- mips_cache_stub.vhdl -- 1-word cache module
3 42 ja_rd
--
4 46 ja_rd
-- This module has the same interface and logic as a real cache but the cache
5
-- memory is just 1 word for each of code and data.
6 43 ja_rd
--
7 46 ja_rd
-- It interfaces the CPU to the following:
8 42 ja_rd
--
9 46 ja_rd
--  1.- Internal 32-bit-wide BRAM for read only
10 42 ja_rd
--  2.- Internal 32-bit I/O bus
11
--  3.- External 16-bit wide SRAM
12
--
13 46 ja_rd
-- The SRAM memory interface signals are meant to connect directly to FPGA pins
14
-- and all outputs are registered (tco should be minimal).
15
-- SRAM data inputs are NOT registered, though. They go through a couple muxes
16
-- before reaching the first register so watch out for tsetup.
17
-- The SRAM is assumed to be fast enough to read or write in a clock cycle.
18 42 ja_rd
--
19 46 ja_rd
-- Obviously this module provides no performance gain; on the contrary, by
20
-- coupling the CPU to slow external memory (16 bit bus) it actually slows it
21
-- down. The purpose of this module is just to test the SRAM interface and the
22
-- cache logic and timing.
23
--
24 42 ja_rd
--------------------------------------------------------------------------------
25 58 ja_rd
-- External FPGA signals
26
--
27
-- This module has signals meant to connect directly to FPGA pins: the SRAM
28
-- interface. They are either direct register outputs or at most with an 
29
-- intervening 2-mux, in order to minimize the Tco (clock-to-output).
30
--
31
-- The Tco of these signals has to be accounted for in the real SRAM interface.
32
-- For example, under Quartus-2 and with a Cyclone-2 grade -7 device, the
33
-- worst Tco for the SRAM data pins is below 5 ns, enough to use a 10ns SRAM
34
-- with a 20 ns clock cycle.
35
-- Anyway, you need to take care of this yourself.
36
--
37
--------------------------------------------------------------------------------
38
-- Interface to CPU
39
--
40
-- 1.- All signals coming from the CPU are registered.
41
-- 2.- All CPU inputs come directly from a register, or at most have a 2-mux in
42
--     between.
43
-- 
44
-- This means this block will not degrade the timing performance of the system, 
45
-- as long as its logic is shallower than the current bottleneck (the ALU).
46
--
47
--------------------------------------------------------------------------------
48 46 ja_rd
-- KNOWN TROUBLE:
49
-- 
50 58 ja_rd
-- Apart from the very rough looks of the code, there's a few known problems:
51 46 ja_rd
--
52
-- 1.- Access to unmapped areas wil crash the CPU
53
--      A couple states are missing in the state machine for handling accesses 
54
--      to unmapped areas. I haven't yet decided how to handle that (return 
55
--      zero, trigger trap, mirror another mapped area...)
56 58 ja_rd
-- 2.- Code refills from SRAM is unimplemented yet
57
--      To be done for sheer lack of time.
58
-- 3.- Address decoding is hardcoded in mips_pkg
59 46 ja_rd
--      It should be done here using module generics and not package constants.
60 58 ja_rd
-- 4.- Does not work as a real 1-word cache yet
61 46 ja_rd
--      That functionality is still missing, all accesses 'miss'. It should be
62
--      implemented, as a way to test the real cache logic on a small scale.
63
--
64
--------------------------------------------------------------------------------
65 42 ja_rd
 
66
library ieee;
67
use ieee.std_logic_1164.all;
68
use ieee.std_logic_arith.all;
69
use ieee.std_logic_unsigned.all;
70
use work.mips_pkg.all;
71
 
72 58 ja_rd
 
73 42 ja_rd
entity mips_cache_stub is
74
    generic (
75
        BRAM_ADDR_SIZE : integer := 10;
76
        SRAM_ADDR_SIZE : integer := 17
77
    );
78
    port(
79
        clk             : in std_logic;
80
        reset           : in std_logic;
81 46 ja_rd
 
82 42 ja_rd
        -- Interface to CPU core
83
        data_rd_addr    : in std_logic_vector(31 downto 0);
84
        data_rd         : out std_logic_vector(31 downto 0);
85
        data_rd_vma     : in std_logic;
86 46 ja_rd
 
87 42 ja_rd
        code_rd_addr    : in std_logic_vector(31 downto 2);
88
        code_rd         : out std_logic_vector(31 downto 0);
89
        code_rd_vma     : in std_logic;
90 46 ja_rd
 
91 42 ja_rd
        data_wr_addr    : in std_logic_vector(31 downto 2);
92
        byte_we         : in std_logic_vector(3 downto 0);
93
        data_wr         : in std_logic_vector(31 downto 0);
94 46 ja_rd
 
95 42 ja_rd
        mem_wait        : out std_logic;
96 46 ja_rd
        cache_enable    : in std_logic;
97
 
98 42 ja_rd
        -- interface to FPGA i/o devices
99
        io_rd_data      : in std_logic_vector(31 downto 0);
100
        io_rd_addr      : out std_logic_vector(31 downto 2);
101
        io_wr_addr      : out std_logic_vector(31 downto 2);
102
        io_wr_data      : out std_logic_vector(31 downto 0);
103
        io_rd_vma       : out std_logic;
104
        io_byte_we      : out std_logic_vector(3 downto 0);
105 46 ja_rd
 
106 42 ja_rd
        -- interface to synchronous 32-bit-wide FPGA BRAM (possibly used as ROM)
107
        bram_rd_data    : in std_logic_vector(31 downto 0);
108
        bram_wr_data    : out std_logic_vector(31 downto 0);
109
        bram_rd_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
110
        bram_wr_addr    : out std_logic_vector(BRAM_ADDR_SIZE+1 downto 2);
111 46 ja_rd
        bram_byte_we    : out std_logic_vector(3 downto 0);
112
        bram_data_rd_vma: out std_logic;
113
 
114 42 ja_rd
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
115 46 ja_rd
        sram_address    : out std_logic_vector(SRAM_ADDR_SIZE downto 1);
116 42 ja_rd
        sram_databus    : inout std_logic_vector(15 downto 0);
117
        sram_byte_we_n  : out std_logic_vector(1 downto 0);
118
        sram_oe_n       : out std_logic
119
    );
120
end entity mips_cache_stub;
121
 
122
 
123
 
124
architecture stub of mips_cache_stub is
125
 
126 58 ja_rd
-- state machines: definition of states -----------------------------
127
 
128 46 ja_rd
type t_code_cache_state is (
129 58 ja_rd
    code_normal,                -- 
130
    code_wait_for_dcache,       -- wait for D-cache to stop using the buses
131 46 ja_rd
 
132
    code_refill_bram_0,         -- pc in bram_rd_addr
133
    code_refill_bram_1,         -- op in bram_rd
134 58 ja_rd
    code_refill_bram_2,         -- op in code_rd 
135 46 ja_rd
 
136 58 ja_rd
    code_refill_sram_0,         -- FIXME code refill from SRAM unimplemented
137 46 ja_rd
    code_refill_sram_1,
138
    code_refill_sram_2,
139
 
140 58 ja_rd
    code_bug                    -- caught an error in the state machine
141 46 ja_rd
   );
142
 
143 58 ja_rd
-- I-cache state machine state register & next state
144 46 ja_rd
signal cps, cns :           t_code_cache_state;
145
 
146
 
147
type t_data_cache_state is (
148
    data_normal,
149
 
150 58 ja_rd
    data_refill_sram_0,         -- rd addr in SRAM addr bus (low hword)
151
    data_refill_sram_1,         -- rd addr in SRAM addr bus (high hword)
152 46 ja_rd
 
153
    data_refill_bram_0,         -- rd addr in bram_rd_addr
154
    data_refill_bram_1,         -- rd data in bram_rd_data
155 42 ja_rd
 
156 46 ja_rd
    data_read_io_0,             -- rd addr on io_rd_addr, io_vma active
157
    data_read_io_1,             -- rd data on io_rd_data
158 58 ja_rd
 
159
    data_write_io_0,            -- wr addr & data in io_wr_*, io_byte_we active
160 46 ja_rd
 
161 58 ja_rd
    data_writethrough_sram_0,   -- wr addr & data in SRAM buses (low hword)
162
    data_writethrough_sram_1,   -- wr addr & data in SRAM buses (high hword)
163 42 ja_rd
 
164 58 ja_rd
    data_ignore_write,          -- hook for raising error flag FIXME untested
165 42 ja_rd
 
166 58 ja_rd
    data_bug                    -- caught an error in the state machine
167 42 ja_rd
   );
168
 
169
 
170 58 ja_rd
-- D-cache state machine state register & next state
171 46 ja_rd
signal dps, dns :           t_data_cache_state;
172 42 ja_rd
 
173 58 ja_rd
-- CPU interface registers ------------------------------------------
174
signal data_rd_addr_reg :   t_pc;
175
signal data_wr_addr_reg :   t_pc;
176
signal code_rd_addr_reg :   t_pc;
177 46 ja_rd
 
178 42 ja_rd
signal data_wr_reg :        std_logic_vector(31 downto 0);
179
signal byte_we_reg :        std_logic_vector(3 downto 0);
180
 
181 58 ja_rd
-- SRAM interface ---------------------------------------------------
182
-- Stores first (high) HW read from SRAM
183
signal sram_rd_data_reg :   std_logic_vector(31 downto 16);
184
-- Data read from SRAM, valid in refill_1
185
signal sram_rd_data :       t_word;
186 46 ja_rd
 
187
 
188 58 ja_rd
 
189
-- I-cache -- most of this is unimplemented -------------------------
190
 
191 46 ja_rd
subtype t_code_tag is std_logic_vector(23 downto 2);
192
signal code_cache_tag :     t_code_tag;
193
signal code_cache_tag_store : t_code_tag;
194
signal code_cache_store :   t_word;
195 58 ja_rd
-- code word read from cache
196 46 ja_rd
signal code_cache_rd :      t_word;
197 58 ja_rd
-- raised whel code_cache_rd is not valid due to a cache miss
198 46 ja_rd
signal code_miss :          std_logic;
199
 
200 58 ja_rd
-- '1' when the I-cache state machine stalls the pipeline (mem_wait)
201
signal code_wait :          std_logic;
202 46 ja_rd
 
203 58 ja_rd
-- D-cache -- most of this is unimplemented -------------------------
204 46 ja_rd
subtype t_data_tag is std_logic_vector(23 downto 2);
205
signal data_cache_tag :     t_data_tag;
206
signal data_cache_tag_store : t_data_tag;
207
signal data_cache_store :   t_word;
208 58 ja_rd
-- active when there's a write waiting to be done
209 46 ja_rd
signal write_pending :      std_logic;
210 58 ja_rd
-- active when there's a read waiting to be done
211 46 ja_rd
signal read_pending :       std_logic;
212 58 ja_rd
-- data word read from cache
213 46 ja_rd
signal data_cache_rd :      t_word;
214 58 ja_rd
-- '1' when data_cache_rd is not valid due to a cache miss
215 46 ja_rd
signal data_miss :          std_logic;
216
 
217 58 ja_rd
-- '1' when the D-cache state machine stalls the pipeline (mem_wait)
218 46 ja_rd
signal data_wait :          std_logic;
219
 
220
 
221 58 ja_rd
-- Address decoding -------------------------------------------------
222
 
223
-- Address slices used to decode
224 46 ja_rd
signal code_rd_addr_mask :  t_addr_decode;
225
signal data_rd_addr_mask :  t_addr_decode;
226
signal data_wr_addr_mask :  t_addr_decode;
227
 
228 58 ja_rd
-- Memory map area being accessed for each of the 3 buses:
229
-- 00 -> BRAM (read only)
230
-- 01 -> SRAM
231
-- 10 -> IO
232
-- 11 -> Unmapped
233 46 ja_rd
signal code_rd_area :       std_logic_vector(1 downto 0);
234
signal data_rd_area :       std_logic_vector(1 downto 0);
235
signal data_wr_area :       std_logic_vector(1 downto 0);
236
 
237 58 ja_rd
 
238
 
239 42 ja_rd
begin
240
 
241 58 ja_rd
--------------------------------------------------------------------------------
242
-- Cache control state machines 
243 42 ja_rd
 
244 46 ja_rd
cache_state_machine_regs:
245 42 ja_rd
process(clk)
246
begin
247
   if clk'event and clk='1' then
248
        if reset='1' then
249 46 ja_rd
            cps <= code_normal;
250
            dps <= data_normal;
251 42 ja_rd
        else
252 46 ja_rd
            cps <= cns;
253
            dps <= dns;
254 42 ja_rd
        end if;
255
    end if;
256 46 ja_rd
end process cache_state_machine_regs;
257 42 ja_rd
 
258 58 ja_rd
-- The code state machine occasionally 'waits' for the 
259 46 ja_rd
code_state_machine_transitions:
260 58 ja_rd
process(cps, dps, code_rd_vma, code_miss, code_rd_area,
261
        write_pending, read_pending)
262 42 ja_rd
begin
263 46 ja_rd
    case cps is
264
    when code_normal =>
265 58 ja_rd
        if code_rd_vma='1' and code_miss='1' and
266
           read_pending='0' and write_pending='0' then
267
            cns <= code_refill_bram_0; -- FIXME check memory area, SRAM!
268 42 ja_rd
        else
269 46 ja_rd
            cns <= cps;
270 42 ja_rd
        end if;
271
 
272 46 ja_rd
    when code_refill_bram_0 =>
273
        cns <= code_refill_bram_1;
274 42 ja_rd
 
275 46 ja_rd
    when code_refill_bram_1 =>
276
        cns <= code_refill_bram_2;
277 42 ja_rd
 
278 46 ja_rd
    when code_refill_bram_2 =>
279
        if dps/=data_normal and read_pending='0' and write_pending='0' then
280
            cns <= code_wait_for_dcache;
281 42 ja_rd
        else
282 46 ja_rd
            cns <= code_normal;
283 42 ja_rd
        end if;
284
 
285 46 ja_rd
    when code_wait_for_dcache =>
286
        -- if D-cache is busy, wait for it to become idle
287
        if dps/=data_normal then
288
            cns <= cps;
289
        elsif code_miss='1' then
290
            cns <= code_refill_bram_1; -- FIXME check memory area
291 42 ja_rd
        else
292 46 ja_rd
            cns <= code_normal;
293 42 ja_rd
        end if;
294
 
295 58 ja_rd
    when code_bug =>
296
        -- Something weird happened, we have 1 cycle to do something like raise
297
        -- an error flag, etc. After 1 cycle, back to normal.
298 46 ja_rd
        cns <= code_normal;
299
 
300 42 ja_rd
    when others =>
301 58 ja_rd
        -- We should never arrive here. If we do we handle it in state code_bug.
302 46 ja_rd
        cns <= code_bug;
303 42 ja_rd
    end case;
304 46 ja_rd
end process code_state_machine_transitions;
305 42 ja_rd
 
306
 
307 58 ja_rd
-- This state machine does not overlap IO/BRAM/SRAM accesses for simplicity.
308
 
309 46 ja_rd
data_state_machine_transitions:
310
process(dps, write_pending, read_pending, data_rd_area, data_wr_area)
311
begin
312
    case dps is
313
    when data_normal =>
314
        if write_pending='1' then
315
            case data_wr_area is
316
            when "00"   => dns <= data_ignore_write; -- Write to BRAM ignored
317
            when "01"   => dns <= data_writethrough_sram_0;
318
            when "10"   => dns <= data_write_io_0;
319
            when others => dns <= dps; -- Write to undecoded area ignored
320
            end case;
321
 
322
        elsif read_pending='1' then
323
            case data_rd_area is
324
            when "00"   => dns <= data_refill_bram_0;
325
            when "01"   => dns <= data_refill_sram_0;
326
            when "10"   => dns <= data_read_io_0;
327
            when others => dns <= dps; -- ignore read from undecoded area
328
                           -- FIXME should raise debug flag 
329
            end case;
330
        else
331
            dns <= dps;
332
        end if;
333 42 ja_rd
 
334 46 ja_rd
    when data_write_io_0 =>
335
        dns <= data_normal;
336
 
337
    when data_read_io_0 =>
338
        dns <= data_read_io_1;
339
 
340
    when data_read_io_1 =>
341
        dns <= data_normal;
342 42 ja_rd
 
343 46 ja_rd
    when data_refill_sram_0 =>
344
        dns <= data_refill_sram_1;
345 42 ja_rd
 
346 46 ja_rd
    when data_refill_sram_1 =>
347
        dns <= data_normal;
348 42 ja_rd
 
349 46 ja_rd
    when data_refill_bram_0 =>
350
        dns <= data_refill_bram_1;
351
 
352
    when data_refill_bram_1 =>
353
        dns <= data_normal;
354
 
355
    when data_writethrough_sram_0 =>
356
        dns <= data_writethrough_sram_1;
357
 
358
    when data_writethrough_sram_1 =>
359
        dns <= data_normal;
360
 
361
    when data_ignore_write =>
362
        dns <= data_normal;
363
 
364
    when data_bug =>
365 58 ja_rd
        -- Something weird happened, we have 1 cycle to do something like raise
366
        -- an error flag, etc. After 1 cycle, back to normal.    
367 46 ja_rd
        dns <= data_normal;
368
 
369
    when others =>
370 58 ja_rd
        -- Should never arrive here. If we do, we handle it in state data_bug.
371 46 ja_rd
        dns <= data_bug;
372
    end case;
373
end process data_state_machine_transitions;
374
 
375
 
376
--------------------------------------------------------------------------------
377
-- CPU interface registers and address decoding --------------------------------
378
 
379
 
380
-- Everything coming and going to the CPU is registered, so that the CPU has
381
-- some timing marging.
382
 
383 58 ja_rd
cpu_data_interface_registers:
384 42 ja_rd
process(clk)
385
begin
386
    if clk'event and clk='1' then
387
        if reset='1' then
388 46 ja_rd
            write_pending <= '0';
389
            read_pending <= '0';
390
            byte_we_reg <= "0000";
391 42 ja_rd
        else
392 46 ja_rd
            -- Raise 'read_pending' at the 1st cycle of a read, clear it when
393
            -- the read (and/or refill) operation has been done.
394
            -- data_rd_addr_reg always has the addr of any pending read
395 42 ja_rd
            if data_rd_vma='1' then
396 46 ja_rd
                read_pending <= '1';
397
                data_rd_addr_reg <= data_rd_addr(31 downto 2);
398
            elsif dps=data_refill_sram_1 or
399
                  dps=data_refill_bram_1 or
400
                  dps=data_read_io_0 then
401
                read_pending <= '0';
402 42 ja_rd
            end if;
403 46 ja_rd
 
404
            -- Raise 'write_pending' at the 1st cycle of a read, clear it when
405
            -- the write (writethrough actually) operation has been done.
406
            -- data_wr_addr_reg always has the addr of any pending write
407
            if byte_we/="0000" and dps=data_normal then
408
                byte_we_reg <= byte_we;
409
                data_wr_reg <= data_wr;
410
                data_wr_addr_reg <= data_wr_addr;
411
                write_pending <= '1';
412
            elsif dps=data_writethrough_sram_1 or
413
                  dps=data_write_io_0 or
414
                  dps=data_ignore_write then
415
                write_pending <= '0';
416
                byte_we_reg <= "0000";
417
            end if;
418 58 ja_rd
 
419
        end if;
420
    end if;
421
end process cpu_data_interface_registers;
422 46 ja_rd
 
423 58 ja_rd
cpu_code_interface_registers:
424
process(clk)
425
begin
426
    if clk'event and clk='1' then
427
        -- Register code fetch addresses only when they are valid; so that
428
        -- code_rd_addr_reg always holds the last fetch address.
429
        if (cps=code_normal and code_rd_vma='1') or
430
            cps=code_refill_bram_2 then -- FIXME explain this term
431
            code_rd_addr_reg <= code_rd_addr;
432 42 ja_rd
        end if;
433
    end if;
434 58 ja_rd
end process cpu_code_interface_registers;
435 42 ja_rd
 
436 58 ja_rd
 
437 46 ja_rd
-- Address decoding ------------------------------------------------------------
438 42 ja_rd
 
439 46 ja_rd
-- Decoding is done on the high bits of the address only, there'll be mirroring.
440
-- Write to areas not explicitly decoded will be silently ignored. Reads will
441
-- get undefined data.
442
 
443
code_rd_addr_mask <= code_rd_addr_reg(31 downto t_addr_decode'low);
444
data_rd_addr_mask <= data_rd_addr_reg(31 downto t_addr_decode'low);
445
data_wr_addr_mask <= data_wr_addr_reg(31 downto t_addr_decode'low);
446
 
447
 
448
with code_rd_addr_mask select code_rd_area <=
449
    "00"    when ADDR_BOOT,
450
    "01"    when ADDR_XRAM,
451
    "11"    when others;
452
 
453
with data_rd_addr_mask select data_rd_area <=
454
    "00"    when ADDR_BOOT,
455
    "01"    when ADDR_XRAM,
456
    "10"    when ADDR_IO,
457
    "11"    when others;
458
 
459
with data_wr_addr_mask select data_wr_area <=
460
    "01"    when ADDR_XRAM,
461
    "10"    when ADDR_IO,
462
    "11"    when others;
463
 
464
--------------------------------------------------------------------------------
465 58 ja_rd
-- BRAM interface
466 46 ja_rd
 
467 58 ja_rd
 
468
-- BRAMm address can come from code or data buses
469
-- (note both inputs to this mux are register outputs)
470
bram_rd_addr <=
471
    data_rd_addr_reg(bram_rd_addr'high downto 2) when dps=data_refill_bram_0
472 46 ja_rd
    else code_rd_addr_reg(bram_rd_addr'high downto 2) ;
473
 
474 58 ja_rd
bram_data_rd_vma <= '1' when dps=data_refill_bram_1 else '0';
475
 
476
 
477
 
478
--------------------------------------------------------------------------------
479
-- Code cache 
480
 
481
-- All the tag match logic is unfinished and will be simplified away in synth.
482
 
483
-- CPU is wired directly to cache output, no muxes
484 46 ja_rd
code_rd <= code_cache_rd;
485
 
486
-- FIXME Actual 1-word cache functionality is unimplemented yet
487 58 ja_rd
code_miss <= '1'; -- always miss
488 46 ja_rd
 
489
-- Read cache code and tag from code store
490
code_cache_rd <= code_cache_store;
491
code_cache_tag <= code_cache_tag_store;
492
 
493
code_cache_memory:
494 42 ja_rd
process(clk)
495
begin
496
    if clk'event and clk='1' then
497 46 ja_rd
 
498
 
499 42 ja_rd
        if reset='1' then
500 46 ja_rd
            -- in the real hardware the tag store can't be reset and it's up
501
            -- to the SW to initialize the cache.
502
            code_cache_tag_store <= (others => '0');
503
            code_cache_store <= (others => '0');
504 42 ja_rd
        else
505 46 ja_rd
            -- Refill cache if necessary
506
            if cps=code_refill_bram_1 then
507
                code_cache_tag_store <=
508
                    "01" & code_rd_addr_reg(t_code_tag'high-2 downto t_code_tag'low);
509
                code_cache_store <= bram_rd_data;
510
            --elsif cps=code_refill_sram_2 then
511
            --    code_cache_tag_store <=
512
            --        "01" & code_rd_addr_reg(t_code_tag'high-2 downto t_code_tag'low);
513
            --    code_cache_store <= sram_rd_data;
514 42 ja_rd
            end if;
515 46 ja_rd
        end if;
516
    end if;
517
end process code_cache_memory;
518
 
519
 
520
--------------------------------------------------------------------------------
521
-- Data cache
522
 
523 58 ja_rd
-- CPU data input mux: direct cache output OR uncached io input
524 46 ja_rd
with dps select data_rd <=
525
    io_rd_data      when data_read_io_1,
526
    data_cache_rd   when others;
527
 
528 58 ja_rd
-- All the tag match logic is unfinished and will be simplified away in synth.
529
-- The 'cache' is really a single register.
530 46 ja_rd
data_cache_rd <= data_cache_store;
531
data_cache_tag <= data_cache_tag_store;
532
 
533
data_cache_memory:
534
process(clk)
535
begin
536
    if clk'event and clk='1' then
537
        if reset='1' then
538
            -- in the real hardware the tag store can't be reset and it's up
539
            -- to the SW to initialize the cache.
540
            data_cache_tag_store <= (others => '0');
541
            data_cache_store <= (others => '0');
542
        else
543
            -- Refill data cache if necessary
544
            if dps=data_refill_sram_1 then
545
                data_cache_tag_store <=
546
                    "01" & data_rd_addr_reg(t_data_tag'high-2 downto t_data_tag'low);
547
                data_cache_store <= sram_rd_data;
548
            elsif dps=data_refill_bram_1 then
549
                data_cache_tag_store <=
550
                    "01" & data_rd_addr_reg(t_data_tag'high-2 downto t_data_tag'low);
551
                data_cache_store <= bram_rd_data;
552 42 ja_rd
            end if;
553
        end if;
554
    end if;
555 46 ja_rd
end process data_cache_memory;
556 42 ja_rd
 
557 58 ja_rd
 
558
--------------------------------------------------------------------------------
559
-- SRAM interface
560
 
561
-- Note this signals are meantto be connected directly to FPGA pins (and then
562
-- to a SRAM, of course). They are the only signals whose tco we care about.
563
 
564
-- FIXME should add a SRAM CE\ signal
565
 
566
-- SRAM address bus (except for LSB) comes from cpu code or data addr registers
567 46 ja_rd
with dps select sram_address(sram_address'high downto 2) <=
568
    data_rd_addr_reg(sram_address'high downto 2)    when data_refill_sram_0,
569
    data_rd_addr_reg(sram_address'high downto 2)    when data_refill_sram_1,
570
    data_wr_addr_reg(sram_address'high downto 2)    when others;
571 42 ja_rd
 
572 58 ja_rd
-- SRAM addr bus LSB depends on the D-cache state because we read/write the
573
-- halfwords sequentially in successive cycles.
574 46 ja_rd
with dps select sram_address(1) <=
575
    '0'     when data_writethrough_sram_0,
576
    '1'     when data_writethrough_sram_1,
577
    '0'     when data_refill_sram_0,
578
    '1'     when data_refill_sram_1,
579
    '0'     when others;
580 42 ja_rd
 
581 58 ja_rd
-- SRAM databus i(when used for output) comes from either hword of the data
582
-- write register.
583 46 ja_rd
with dps select sram_databus <=
584
    data_wr_reg(31 downto 16)   when data_writethrough_sram_0,
585
    data_wr_reg(15 downto  0)   when data_writethrough_sram_1,
586
    (others => 'Z')             when others;
587 42 ja_rd
 
588 58 ja_rd
-- The byte_we is split in two similarly.
589 46 ja_rd
with dps select sram_byte_we_n <=
590
    not byte_we_reg(3 downto 2) when data_writethrough_sram_0,
591
    not byte_we_reg(1 downto 0) when data_writethrough_sram_1,
592
    "11"                        when others;
593 42 ja_rd
 
594 58 ja_rd
-- SRAM OE\ is only asserted low for read cycles
595 46 ja_rd
with dps select sram_oe_n <=
596
    '0' when data_refill_sram_0,
597
    '0' when data_refill_sram_1,
598
    '1' when others;
599 42 ja_rd
 
600 58 ja_rd
-- When eading from the SRAM, read word comes from read hword register and 
601
-- SRAM bus (read register is loaded in previous cycle).
602 46 ja_rd
sram_rd_data <= sram_rd_data_reg & sram_databus;
603 42 ja_rd
 
604 58 ja_rd
sram_input_halfword_register:
605 46 ja_rd
process(clk)
606
begin
607
    if clk'event and clk='1' then
608 58 ja_rd
        sram_rd_data_reg <= sram_databus;
609 46 ja_rd
    end if;
610 58 ja_rd
end process sram_input_halfword_register;
611 42 ja_rd
 
612
 
613
--------------------------------------------------------------------------------
614 58 ja_rd
-- I/O interface -- IO is assumed to behave like synchronous memory
615 42 ja_rd
 
616 46 ja_rd
io_byte_we <= byte_we_reg when dps=data_write_io_0 else "0000";
617
io_rd_addr <= data_rd_addr_reg;
618
io_wr_addr <= data_wr_addr_reg;
619
io_wr_data <= data_wr_reg;
620
io_rd_vma <= '1' when dps=data_read_io_0 else '0';
621 42 ja_rd
 
622 58 ja_rd
 
623 46 ja_rd
--------------------------------------------------------------------------------
624 58 ja_rd
-- CPU stall control
625 42 ja_rd
 
626 58 ja_rd
-- Stall the CPU when either state machine needs it
627 46 ja_rd
mem_wait <= (code_wait or data_wait) and not reset;
628 42 ja_rd
 
629 58 ja_rd
-- Assert code_wait until the cycle where the CPU has valid code word on its
630
-- code bus
631 46 ja_rd
with cps select code_wait <=
632
    '1' when code_refill_bram_0,
633
    '1' when code_refill_bram_1,
634
    '1' when code_refill_bram_2,
635
    '1' when code_wait_for_dcache,
636
    '0' when others;
637 42 ja_rd
 
638 58 ja_rd
-- Assert code_wait until the cycle where the CPU has valid data word on its
639
-- code bus AND no other operations are ongoing that may use the external buses.
640 46 ja_rd
with dps select data_wait <=
641
    '1' when data_writethrough_sram_0,
642
    '1' when data_writethrough_sram_1,
643
    '1' when data_refill_sram_0,
644
    '1' when data_refill_sram_1,
645
    '1' when data_refill_bram_0,
646
    '1' when data_refill_bram_1,
647
    '1' when data_read_io_0,
648
    '0' when others;
649
 
650 42 ja_rd
end architecture stub;

powered by: WebSVN 2.1.0

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