aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock20
-rw-r--r--Cargo.toml7
-rw-r--r--src/main.rs57
4 files changed, 86 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7aef303
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+target
+*~
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..3c80b43
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,20 @@
+[root]
+name = "cacheracer"
+version = "0.1.0"
+dependencies = [
+ "rustv 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "elfloader32"
+version = "0.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rustv"
+version = "0.2.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/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..79086b6
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "cacheracer"
+version = "0.1.0"
+authors = ["David Li <li.davidm96@gmail.com>"]
+
+[dependencies]
+rustv = "0.2.1"
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..b27a89c
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,57 @@
+extern crate rustv;
+
+use std::fs::File;
+use std::io::Read;
+use std::rc::Rc;
+use std::cell::RefCell;
+use rustv::elfloader;
+use rustv::isa;
+use rustv::memory;
+use rustv::simulator;
+
+fn main() {
+ let mut f = File::open("../riscv/kernel").unwrap();
+ let mut buffer = Vec::new();
+
+ f.read_to_end(&mut buffer).unwrap();
+
+ let elf = elfloader::ElfBinary::new("test", &buffer).unwrap();
+ let start = elf.file_header().entry as isa::Address;
+
+ let mut text = None;
+ let mut data = None;
+ for p in elf.section_headers() {
+ if p.name.0 == 0x1b {
+ text = Some((elf.section_data(p), p.addr));
+ }
+ else if p.name.0 == 0x33 {
+ data = Some((elf.section_data(p), p.addr));
+ }
+ }
+
+ let (text, text_offset) = text.unwrap();
+ let (data, data_offset) = data.unwrap();
+
+ let mmu = memory::IdentityMmu::new();
+ let mmu2 = memory::ReverseMmu::new(0x8000);
+ let mut memory = memory::Memory::new(0x10000);
+ memory.write_segment(&mmu, text, text_offset as usize);
+ memory.write_segment(&mmu, data, data_offset as usize);
+ memory.write_segment(&mmu2, text, text_offset as usize);
+ memory.write_segment(&mmu2, data, data_offset as usize);
+
+ let memory_box = Box::new(memory) as Box<memory::MemoryInterface>;
+ let memory_ref = Rc::new(RefCell::new(memory_box));
+ let cache = memory::DirectMappedCache::new(4, 4, memory_ref.clone());
+ let cache_box = Box::new(cache) as Box<memory::MemoryInterface>;
+ let cache_ref = Rc::new(RefCell::new(cache_box));
+ let core = simulator::Core::new(
+ start, 0x1000,
+ cache_ref.clone(), Box::new(mmu));
+ let core2 = simulator::Core::new(
+ start, 0x3000,
+ cache_ref.clone(), Box::new(mmu2));
+ let cores = vec![core, core2];
+ let mut simulator = simulator::Simulator::new(cores, memory_ref.clone());
+ simulator.run();
+}