aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2016-01-04 18:30:23 -0700
committerDavid Li <li.davidm96@gmail.com>2016-01-04 18:30:23 -0700
commit6b3d1df04776406a39b3fd0fab18e49b92c84190 (patch)
treeda3e8ca5c302342661f966d2ebec2c242e92530c
parentbb8162c22e34ac588f92b4d3783c39d04a67ec2c (diff)
Make memory construction from segments a method instead
-rw-r--r--src/lib.rs7
-rw-r--r--src/memory.rs22
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<memory::MemoryInterface>));
let cache = Rc::new( RefCell::new( Box::new( memory::DirectMappedCache::new(4, 4, memory_ref.clone())) as Box<memory::MemoryInterface>) );
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);
}
}