From 32428a6bbdb43d8c8948ddcfe66db637219f3d03 Mon Sep 17 00:00:00 2001
From: David Li
Date: Wed, 6 Jan 2016 09:17:53 -0700
Subject: Parse command line arguments
---
src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 8 deletions(-)
(limited to 'src')
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
+
+Options:
+ -h --help Show this screen.
+ --version Show version.
+";
+
+#[derive(Debug, RustcDecodable)]
+struct Args {
+ arg_program1: String,
+ arg_program2: String,
+}
+
+fn load_program(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;
let memory_ref = Rc::new(RefCell::new(memory_box));
@@ -46,10 +79,10 @@ fn main() {
let cache_box = Box::new(cache) as Box;
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());
--
cgit v1.2.3