From 2a5bbfe8131e5e863824009cb0eec3d4599d5d7b Mon Sep 17 00:00:00 2001
From: David Li
Date: Tue, 5 Jan 2016 11:03:17 -0700
Subject: Initial commit
---
src/main.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 src/main.rs
(limited to 'src')
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;
+ 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;
+ 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();
+}
--
cgit v1.2.3