[][src]Struct riscy::Addr

pub struct Addr(_);

A struct to representing an address value.

Addresses in rv32i are 32-bits wide. We usually write them out in hexadecimal.

Addrs are used in the interface of the Memory trait. An Addr is used to name the location of a specific byte in the memory space.

An important operation for operating for working with Addrs is adding or subtracting an offset. Several RISC-V instructions take a register together with a small immediate value (for example, lw, load word, and jalr, jump-and-link return). The value in the register becomes the base address, but the instruction then operates on memory on a small distance away from the base address. And so, several integer types, (including u32, i32, and RegVal can be added to an Addr.

When using offsets, the order must be: Addr + offset.

It doesn't make sense to add an Addr to another Addr, so this operation is not provided.

Addrs may be converted to RegVals and vice versa:

let value = RegVal::from_u32(0x2000_0000);
let addr: Addr = value.into();
let new_value = (addr + 0x0a).into();

Addrs can also be compared with <, <=, etc. This is useful for certain implementations of Memory which would like to store Addrs in BTreeMaps.

While Addr (together with the Memory interface) give every byte in memory a unique address, physical hardware often operates with memory on the level of words. That is, it is common that memory might only operate on groups of four bytes. Because of this, some operations will only work when the Addr has a proper alignment.

No restrictions on alignment are given in this version of riscy, but this is subject (and likely) to change in future versions.

Implementations

impl Addr[src]

pub fn new(addr: u32) -> Addr[src]

Trait Implementations

impl Add<RegVal> for Addr[src]

type Output = Addr

The resulting type after applying the + operator.

impl Add<i32> for Addr[src]

type Output = Addr

The resulting type after applying the + operator.

impl Add<u32> for Addr[src]

type Output = Addr

The resulting type after applying the + operator.

impl Add<usize> for Addr[src]

type Output = Addr

The resulting type after applying the + operator.

impl AddAssign<RegVal> for Addr[src]

impl AddAssign<i32> for Addr[src]

impl AddAssign<u32> for Addr[src]

impl AddAssign<usize> for Addr[src]

impl Clone for Addr[src]

impl Copy for Addr[src]

impl Debug for Addr[src]

impl Display for Addr[src]

impl Eq for Addr[src]

impl From<Addr> for u32[src]

impl From<Addr> for usize[src]

impl From<Addr> for RegVal[src]

impl From<RegVal> for Addr[src]

impl Hash for Addr[src]

impl Ord for Addr[src]

impl PartialEq<Addr> for Addr[src]

impl PartialOrd<Addr> for Addr[src]

impl StructuralEq for Addr[src]

impl StructuralPartialEq for Addr[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.