Skip to main content

Cpu

Struct Cpu 

Source
pub struct Cpu {
    pub csrs: Csrs,
    /* private fields */
}
Expand description

The processor.

Fields§

§csrs: Csrs

Control 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

Source

pub fn new(entry: Word) -> Cpu

A processor with every register zero, starting at entry.

Source

pub fn reg(&self, r: Reg) -> Word

Reads a register. r0 always reads zero.

Source

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.

Source

pub fn pc(&self) -> Word

The program counter - the tryte address of the next instruction.

Source

pub fn set_pc(&mut self, pc: Word)

Sets the program counter.

Source

pub fn halted(&self) -> bool

True once a halt has executed.

Source

pub fn steps(&self) -> u64

How many instructions have executed.

Source

pub fn privilege(&self) -> Priv

The current privilege level.

Source

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.

Source

pub fn reg_value(&self, n: i8) -> i64

The value in register n, numbered -13 to 13.

§Panics

If n is outside the register range.

Source

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.

Source

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.

Source

pub fn run<A: Addressable>( &mut self, mem: &mut A, max_steps: u64, ) -> Result<Halted, Trap>

Runs until halt or trap, at most max_steps instructions. The budget bounds programs that do not terminate.

Trait Implementations§

Source§

impl Clone for Cpu

Source§

fn clone(&self) -> Cpu

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Cpu

§

impl RefUnwindSafe for Cpu

§

impl Send for Cpu

§

impl Sync for Cpu

§

impl Unpin for Cpu

§

impl UnsafeUnpin for Cpu

§

impl UnwindSafe for Cpu

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.