pub struct Cpu {
pub csrs: Csrs,
/* private fields */
}Expand description
The processor.
Fields§
§csrs: CsrsControl and status registers. Public so a host can set a trap vector or inspect a cause without going through guest instructions.
Implementations§
Source§impl Cpu
impl Cpu
Sourcepub fn set_reg(&mut self, r: Reg, value: Word)
pub fn set_reg(&mut self, r: Reg, value: Word)
Writes a register. Writes to r0 are discarded, which lets r0 serve
as a destination for instructions run only for their side effects, such
as jalr r0, r3, 0 to return without saving a link.
Sourcepub fn set_privilege(&mut self, level: Priv)
pub fn set_privilege(&mut self, level: Priv)
Sets the privilege level directly.
For a host bringing a machine up, or a test. A guest changes privilege
only by taking a trap or executing tret.
Sourcepub fn load_word<A: Addressable>(
&self,
virt: i64,
mem: &mut A,
) -> Result<Word, Trap>
pub fn load_word<A: Addressable>( &self, virt: i64, mem: &mut A, ) -> Result<Word, Trap>
Loads a word through translation, as an instruction would.
Exposed so a host or a test can see what an address means at the machine’s current privilege without assembling a program to do it.
Sourcepub fn step<A: Addressable>(&mut self, mem: &mut A) -> Result<bool, Trap>
pub fn step<A: Addressable>(&mut self, mem: &mut A) -> Result<bool, Trap>
Executes one instruction. Returns Ok(false) once halted; further
calls do nothing.
§Traps
What a trap does depends on whether an operating system has claimed
them. With tvec zero, which is the reset state, a trap stops the
machine and is returned to the host. With tvec set, the trap is
vectored to the handler and step returns normally, so a program that
faults no longer takes the machine down.