diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/shareable_cache.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/shareable_cache.rs b/src/shareable_cache.rs index 3a2dd56..503c7d5 100644 --- a/src/shareable_cache.rs +++ b/src/shareable_cache.rs @@ -1,7 +1,8 @@ use std::collections::HashSet; use rustv::isa::{self, IsaType}; -use rustv::memory::{MemoryError, MemoryInterface, Result, SharedMemory}; +use rustv::memory::{CacheInterface, CacheMetadata, MemoryError, MemoryInterface, + Result, SharedCache, SharedMemory}; pub const WRITE_TRAP_VALUE: isa::Byte = isa::Byte(0xE0); pub const AREA_TRAP_VALUE: isa::Byte = isa::Byte(0xE4); @@ -13,14 +14,16 @@ pub const WRITE_TRAP_SET_STALL: u32 = 100; /// set-associative cache. pub struct ShareableCache<'a> { core_id: usize, - primary: SharedMemory<'a>, - secondary: SharedMemory<'a>, + primary: SharedCache<'a>, + secondary: SharedCache<'a>, secondary_enabled: bool, use_secondary: bool, traps_hit: HashSet<isa::Address>, } -// Cache snooping: update all cache lines when a write is made +/// Cache snooping: update the secondary cache when the primary cache +/// is written to. This is a macro in order to be generic with regard +/// to the size of the write. macro_rules! snoop { ($cache: expr, $write_value: ident, $address: ident, $value: ident) => { if $cache.borrow().is_address_accessible($address) { @@ -31,6 +34,9 @@ macro_rules! snoop { } } +/// Check whether the write sets off any traps, and stall if +/// appropriate. This is a macro in order to be generic with regard to +/// the size of the write. macro_rules! check_traps { ($core_id: expr, $cache: expr, $traps_hit: expr, $write_value: ident, $address: ident, $value: ident) => {{ @@ -175,7 +181,7 @@ macro_rules! write_value { impl<'a> ShareableCache<'a> { pub fn new(core_id: usize, - cache1: SharedMemory<'a>, cache2: SharedMemory<'a>) + cache1: SharedCache<'a>, cache2: SharedCache<'a>) -> ShareableCache<'a> { ShareableCache { core_id: core_id, @@ -271,3 +277,10 @@ impl<'a> MemoryInterface for ShareableCache<'a> { write_value!(self, write_byte, address, value) } } + +impl<'a> CacheInterface for ShareableCache<'a> { + fn cache_metadata(&self) -> CacheMetadata { + // TODO: merge tags in secondary enabled mode + self.primary.borrow().cache_metadata() + } +} |