Struct lc3_ensemble::sim::Simulator
source · pub struct Simulator {
pub mem: Mem,
pub reg_file: RegFile,
pub pc: u16,
pub strict: bool,
pub breakpoints: Vec<Breakpoint>,
/* private fields */
}Expand description
Executes assembled code.
Fields§
§mem: MemThe simulator’s memory.
Note that this is held in the heap, as it is too large for the stack.
reg_file: RegFileThe simulator’s register file.
pc: u16The program counter.
strict: boolWhether strict mode is enabled.
Strict mode adds additional integrity checks to the simulator, such as verifying initialization state is normal for provided data.
breakpoints: Vec<Breakpoint>Breakpoints for the simulator.
Implementations§
source§impl Simulator
impl Simulator
sourcepub fn new(strat: WordCreateStrategy) -> Self
pub fn new(strat: WordCreateStrategy) -> Self
Creates a new simulator with the provided initializers and with the OS loaded, but without a loaded object file.
sourcepub fn load_os(&mut self)
pub fn load_os(&mut self)
Loads and initializes the operating system.
Note that this is done automatically with Simulator::new.
This will initialize kernel space and create trap handlers,
however it will not load working IO. This can cause IO
traps such as GETC and PUTC to hang. The only trap that
is assured to function without IO is HALT.
To initialize the IO, use Simulator::open_io.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the simulator.
This sets the simulator back to the state it was in when Simulator::new was called.
Essentially, this resets all state fields back to their defaults,
and the memory and register file back to their original initialization values
(unless the creation strategy used to initialize this Simulator was WordCreateStrategy::Unseeded).
sourcepub fn load_obj_file(&mut self, obj: &ObjectFile)
pub fn load_obj_file(&mut self, obj: &ObjectFile)
Loads an object file into this simulator.
sourcepub fn mcr(&self) -> &Arc<AtomicBool>
pub fn mcr(&self) -> &Arc<AtomicBool>
Gets a reference to the MCR.
sourcepub fn set_pc(
&mut self,
addr_word: Word,
st_check_mem: bool
) -> Result<(), SimErr>
pub fn set_pc( &mut self, addr_word: Word, st_check_mem: bool ) -> Result<(), SimErr>
Sets the PC to the given address, raising any errors that occur.
The st_check_mem parameter indicates whether the data at the PC should be verified in strict mode.
This should be enabled when it is absolutely known that the PC will read from the provided address
on the next cycle.
This should be true when this function is used for instructions like BR and JSR
and should be false when this function is used to increment PC during fetch.
sourcepub fn offset_pc(
&mut self,
offset: i16,
st_check_mem: bool
) -> Result<(), SimErr>
pub fn offset_pc( &mut self, offset: i16, st_check_mem: bool ) -> Result<(), SimErr>
Adds an offset to the PC.
See Simulator::set_pc for details about st_check_mem.
sourcepub fn prefetch_pc(&self) -> u16
pub fn prefetch_pc(&self) -> u16
Gets the value of the prefetch PC.
This function returns the value of PC before it is incremented druing fetch, which is also the location of the currently executing instruction in memory.
This is useful for pointing to a given memory location in error handling, as this computation always points to the memory location of the instruction.
sourcepub fn hit_breakpoint(&self) -> bool
pub fn hit_breakpoint(&self) -> bool
Indicates whether the last execution of the simulator hit a breakpoint.
sourcepub fn default_mem_ctx(&self) -> MemAccessCtx
pub fn default_mem_ctx(&self) -> MemAccessCtx
Computes the default memory access context,
which are the default flags to use (see Mem::read and Mem::write).