diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-06 09:17:53 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-06 09:17:53 -0700 |
commit | 32428a6bbdb43d8c8948ddcfe66db637219f3d03 (patch) | |
tree | ec973282efe4a20392559f2ddb1934e800b48992 /src | |
parent | 2a5bbfe8131e5e863824009cb0eec3d4599d5d7b (diff) |
Parse command line arguments
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index b27a89c..15b4fba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,39 @@ +extern crate docopt; +extern crate rustc_serialize; extern crate rustv; use std::fs::File; use std::io::Read; use std::rc::Rc; use std::cell::RefCell; + +use docopt::Docopt; + use rustv::elfloader; use rustv::isa; use rustv::memory; use rustv::simulator; -fn main() { - let mut f = File::open("../riscv/kernel").unwrap(); +const USAGE: &'static str = " +cacheracer - A F/OSS implementation of the CS 3410 CacheRacer + +Usage: + cacheracer <program1> <program2> + +Options: + -h --help Show this screen. + --version Show version. +"; + +#[derive(Debug, RustcDecodable)] +struct Args { + arg_program1: String, + arg_program2: String, +} + +fn load_program<T: memory::Mmu>(memory: &mut memory::Memory, + mmu: &T, path: &str) -> isa::Address { + let mut f = File::open(path).unwrap(); let mut buffer = Vec::new(); f.read_to_end(&mut buffer).unwrap(); @@ -32,13 +55,23 @@ fn main() { let (text, text_offset) = text.unwrap(); let (data, data_offset) = data.unwrap(); + memory.write_segment(mmu, text, text_offset as usize); + memory.write_segment(mmu, data, data_offset as usize); + + start +} + +fn main() { + let args: Args = Docopt::new(USAGE) + .and_then(|d| d.decode()) + .unwrap_or_else(|e| e.exit()); + 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 start1 = load_program(&mut memory, &mmu, &args.arg_program1); + let start2 = load_program(&mut memory, &mmu2, &args.arg_program2); let memory_box = Box::new(memory) as Box<memory::MemoryInterface>; let memory_ref = Rc::new(RefCell::new(memory_box)); @@ -46,10 +79,10 @@ fn main() { 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, + start1, 0x1000, cache_ref.clone(), Box::new(mmu)); let core2 = simulator::Core::new( - start, 0x3000, + start2, 0x1000, cache_ref.clone(), Box::new(mmu2)); let cores = vec![core, core2]; let mut simulator = simulator::Simulator::new(cores, memory_ref.clone()); |