Expand description
An InstructionProcessor that executes instructions.
The InstructionExecutor takes a HartState and a Memory. The HartState is updated by the instruction execution using the Memory for all memory accesses. A InstructionExecutor::step function is provided to deal with reading the next instruction from the memory, updating the PC appropriately and wraps the call to process_instruction()`.
§Example
use rrs_lib::HartState;
use rrs_lib::memories::VecMemory;
use rrs_lib::instruction_executor::{InstructionExecutor, InstructionException};
let mut hart = HartState::new();
// Memory contains these instructions:
// lui x2, 0x1234b
// lui x3, 0xf387e
// add x1, x2, x3
let mut mem = VecMemory::new(vec![0x1234b137, 0xf387e1b7, 0x003100b3]);
hart.pc = 0;
let mut executor = InstructionExecutor {
hart_state: &mut hart,
mem: &mut mem,
};
assert_eq!(executor.step(), Ok(()));
assert_eq!(executor.hart_state.registers[2], 0x1234b000);
assert_eq!(executor.step(), Ok(()));
assert_eq!(executor.hart_state.registers[3], 0xf387e000);
assert_eq!(executor.step(), Ok(()));
assert_eq!(executor.hart_state.registers[1], 0x05bc9000);
// Memory only contains three instructions so next step will produce a fetch error
assert_eq!(executor.step(), Err(InstructionException::FetchError(0xc)));
Structs§
- Instruction
Executor - An
InstructionProcessor
that execute instructions, updatinghart_state
as appropriate.
Enums§
- Instruction
Exception - Different exceptions that can occur during instruction execution