aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-05 11:03:17 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-05 11:03:17 -0700
commit2a5bbfe8131e5e863824009cb0eec3d4599d5d7b (patch)
tree39cc76d4965a4177e157c878da02c2ac046728e5 /src
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/main.rs57
1 files changed, 57 insertions, 0 deletions
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();
+}