aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock4
-rw-r--r--src/shareable_cache.rs23
2 files changed, 20 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bf0cee2..8694529 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7,7 +7,7 @@ dependencies = [
"log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustv 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustv 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -114,7 +114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustv"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elfloader32 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
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()
+ }
+}