Struct riscy::RiscV

source ·
pub struct RiscV { /* private fields */ }
Expand description

A struct to hold the state of a RiscV core.

Implementations§

source§

impl RiscV

source

pub fn new() -> Self

Create a new RiscV core with all of its registers zeroed out.

source

pub fn step<M: Memory>(&mut self, memory: &mut M) -> StepResult

Fetch, execute, and retire a single instruction. When the core attempts to interact with memory, whether to fetch an instruction, to perform a load or store operation, etc, it makes use of the supplied memory.

source

pub fn step_with_retired<M: Memory>( &mut self, memory: &mut M ) -> (StepResult, Option<Instruction>)

Same as step, but returns the decoded instruction.

source

pub fn set_reg<R: Into<Reg>>(&mut self, reg: R, reg_val: RegVal)

Sets the given register to the given value.

// sets the the stack pointer, `sp`, (also known as `x2`) to the value `0x2000_0000`.
riscv.set_reg(2, 0x2000_0000.into());
source

pub fn reg<R: Into<Reg>>(&self, reg: R) -> RegVal

Gets the value of the given register.

// gets the value of the return address register, `ra`, (also known as `x1`).
riscv.reg(1);
source

pub fn set_pc(&mut self, addr: Addr)

Sets the value of the program counter to the given address.

This is useful for specifying the entry point to the program when first initializing the machine.

source

pub fn pc(&self) -> Addr

Gets the value of the program counter.

Trait Implementations§

source§

impl Display for RiscV

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for RiscV

§

impl Send for RiscV

§

impl Sync for RiscV

§

impl Unpin for RiscV

§

impl UnwindSafe for RiscV

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.