diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-04 19:01:24 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-04 19:01:24 -0700 |
commit | db87cd3953eef9ec78c3a17ce6d21055cf879ab8 (patch) | |
tree | 020548b68a01bf57c3f460d90dca7ee49fa1fd72 /src/memory.rs | |
parent | 7c2e626e99c6167444de52fb63509814644a11a3 (diff) |
Enable loading with address translation
Diffstat (limited to 'src/memory.rs')
-rw-r--r-- | src/memory.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/memory.rs b/src/memory.rs index b90170b..b618001 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -160,7 +160,7 @@ pub struct DirectMappedCache<'a> { next_level: SharedMemory<'a>, } -fn copy_u8_into_u32(src: &[u8], dst: &mut [u32]) { +fn copy_u8_into_u32<T: Mmu>(mmu: &T, base: usize, src: &[u8], dst: &mut [u32]) { for (offset, word) in src.chunks(4).enumerate() { let word = if word.len() == 4 { (word[0] as u32) | @@ -181,7 +181,8 @@ fn copy_u8_into_u32(src: &[u8], dst: &mut [u32]) { word[0] as u32 }; - dst[offset] = word; + let addr = mmu.translate((base as isa::Address) + ((4 * offset) as isa::Address)) / 4; + dst[addr as usize] = word; } } @@ -204,10 +205,9 @@ impl 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); + pub fn write_segment<T: Mmu>(&mut self, mmu: &T, + data: &[u8], offset: usize) { + copy_u8_into_u32(mmu, offset, data, &mut self.memory); } } |