diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/memory.rs | 22 |
2 files changed, 7 insertions, 22 deletions
@@ -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); } } |