diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-03 13:47:01 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-03 13:47:01 -0700 |
commit | 01f161fa1ac86e75524bf038e51a236f0dfb22a6 (patch) | |
tree | ea8287ce33ecb68c384b90c5343cf208ab459576 /src/memory.rs | |
parent | e70bcb8e1838f5c88cdea19967835f112a8f1bd8 (diff) |
Add MMU to core
Diffstat (limited to 'src/memory.rs')
-rw-r--r-- | src/memory.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/memory.rs b/src/memory.rs index 9f14700..92aefd5 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -89,7 +89,38 @@ pub trait MemoryInterface { pub type SharedMemory<'a> = Rc<RefCell<Box<MemoryInterface + 'a>>>; pub trait Mmu { - fn translate(address: isa::Address) -> isa::Address; + fn translate(&self, address: isa::Address) -> isa::Address; +} + +pub struct IdentityMmu {} +pub struct ReverseMmu { + top: isa::Address, +} + +impl IdentityMmu { + pub fn new() -> IdentityMmu { + IdentityMmu {} + } +} + +impl Mmu for IdentityMmu { + fn translate(&self, address: isa::Address) -> isa::Address { + address + } +} + +impl ReverseMmu { + pub fn new(top: isa::Address) -> ReverseMmu { + ReverseMmu { + top: top, + } + } +} + +impl Mmu for ReverseMmu { + fn translate(&self, address: isa::Address) -> isa::Address { + self.top - address + } } pub struct Memory { |