diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-17 17:11:44 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-17 17:11:44 -0700 |
commit | e46c829c3703be25c457e75bb7f46c05694f5e75 (patch) | |
tree | 231e047275f9d481f8d1c49db3a82d76a55fca6e /src | |
parent | b06b9ad97e82ea66303c389f72454ff7a7297052 (diff) |
Implement rustv::memory::CacheInterface
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() + } +} |