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 | |
parent | 2a5bbfe8131e5e863824009cb0eec3d4599d5d7b (diff) |
Parse command line arguments
-rw-r--r-- | Cargo.lock | 58 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 49 |
3 files changed, 101 insertions, 8 deletions
@@ -2,15 +2,68 @@ name = "cacheracer" version = "0.1.0" dependencies = [ + "docopt 0.6.78 (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.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] +name = "aho-corasick" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "docopt" +version = "0.6.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "regex 0.1.46 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.3.0 (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 = "libc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustc-serialize" +version = "0.3.16" +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" @@ -18,3 +71,8 @@ dependencies = [ "elfloader32 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + @@ -5,3 +5,5 @@ authors = ["David Li <li.davidm96@gmail.com>"] [dependencies] rustv = "0.2.1" +docopt = "0.6" +rustc-serialize = "0.3" 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()); |