Struct lc3_ensemble::sim::mem::Mem
source · pub struct Mem { /* private fields */ }Expand description
Memory. This can be addressed with any u16.
Implementations§
source§impl Mem
impl Mem
sourcepub fn new(strat: &mut WordCreateStrategy) -> Self
pub fn new(strat: &mut WordCreateStrategy) -> Self
Creates a new memory with a provided word creation strategy.
sourcepub fn copy_obj_block(&mut self, start: u16, data: &[Option<u16>])
pub fn copy_obj_block(&mut self, start: u16, data: &[Option<u16>])
Copies an object file block into this memory.
sourcepub fn get_raw(&self, addr: u16) -> &Word
pub fn get_raw(&self, addr: u16) -> &Word
Gets a reference to a word from the memory’s current state.
This is only meant to be used to query the state of the memory, not to simulate a read from memory.
Note the differences from Mem::read:
- This function does not trigger IO effects (and as a result, IO values will not be updated).
- This function does not require
MemAccessCtx. - This function does not perform access violation checks.
If any of these effects are necessary (e.g., when trying to execute instructions from the simulator),
Mem::read should be used instead.
sourcepub fn get_raw_mut(&mut self, addr: u16) -> &mut Word
pub fn get_raw_mut(&mut self, addr: u16) -> &mut Word
Gets a mutable reference to a word from the memory’s current state.
This is only meant to be used to query/edit the state of the memory, not to simulate a write from memory.
Note the differences from Mem::write:
- This function does not trigger IO effects (and as a result, IO values will not be updated).
- This function does not require
MemAccessCtx. - This function does not perform access violation checks or strict uninitialized memory checking.
If any of these effects are necessary (e.g., when trying to execute instructions from the simulator),
Mem::write should be used instead.
sourcepub fn read(&mut self, addr: u16, ctx: MemAccessCtx) -> Result<Word, SimErr>
pub fn read(&mut self, addr: u16, ctx: MemAccessCtx) -> Result<Word, SimErr>
Fallibly reads the word at the provided index, erroring if not possible.
This accepts a MemAccessCtx, that describes the parameters of the memory access.
The simulator provides a default MemAccessCtx under super::Simulator::default_mem_ctx.
The flags are used as follows:
privileged: if false, this access errors if the address is a memory location outside of the user range.strict: not used forread
Note that this method is used for simulating a read. If you would like to query the memory’s state,
consider Mem::get_raw.
sourcepub fn write(
&mut self,
addr: u16,
data: Word,
ctx: MemAccessCtx
) -> Result<(), SimErr>
pub fn write( &mut self, addr: u16, data: Word, ctx: MemAccessCtx ) -> Result<(), SimErr>
Fallibly writes the word at the provided index, erroring if not possible.
This accepts a MemAccessCtx, that describes the parameters of the memory access.
The simulator provides a default MemAccessCtx under super::Simulator::default_mem_ctx.
The flags are used as follows:
privileged: if false, this access errors if the address is a memory location outside of the user range.strict: If true, all accesses that would cause a memory location to be set with uninitialized data causes an error.
Note that this method is used for simulating a write. If you would like to edit the memory’s state,
consider Mem::get_raw_mut.