From 6b3d1df04776406a39b3fd0fab18e49b92c84190 Mon Sep 17 00:00:00 2001
From: David Li
Date: Mon, 4 Jan 2016 18:30:23 -0700
Subject: Make memory construction from segments a method instead
---
src/lib.rs | 7 +++----
src/memory.rs | 22 ++++------------------
2 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
index 35951c2..7cf0920 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -52,10 +52,9 @@ fn test_elfloader() {
let mmu = memory::IdentityMmu::new();
// TODO: make this a method; have it accept a MMU
- let memory = memory::Memory::new_from_text_and_data(
- 0x8000,
- text, text_offset as usize,
- data, data_offset as usize);
+ let mut memory = memory::Memory::new(0x8000);
+ memory.write_segment(text, text_offset as usize);
+ memory.write_segment(data, data_offset as usize);
let memory_ref = Rc::new(RefCell::new(Box::new(memory) as Box));
let cache = Rc::new( RefCell::new( Box::new( memory::DirectMappedCache::new(4, 4, memory_ref.clone())) as Box) );
let core = simulator::Core::new(start, 0x1000, cache.clone(), Box::new(mmu));
diff --git a/src/memory.rs b/src/memory.rs
index 9bc3643..371a0a3 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -201,24 +201,10 @@ impl Memory {
}
}
- pub fn new_from_text_and_data(size: usize,
- text: &[u8], text_offset: usize,
- data: &[u8], data_offset: usize) -> Memory {
- let mut memory = vec![0; size];
-
- {
- let mut text_segment = &mut memory[(text_offset / 4)..size];
- copy_u8_into_u32(text, text_segment);
- }
-
- {
- let mut data_segment = &mut memory[(data_offset / 4)..size];
- copy_u8_into_u32(data, data_segment);
- }
-
- Memory {
- memory: memory,
- }
+ pub fn write_segment(&mut self, data: &[u8], offset: usize) {
+ let size = self.memory.len();
+ let mut segment = &mut self.memory[(offset / 4)..size];
+ copy_u8_into_u32(data, segment);
}
}
--
cgit v1.2.3