pub struct Addr(/* private fields */);
Expand description
A struct to representing an address value.
Addresses in rv32i are 32-bits wide. We usually write them out in hexadecimal.
Addr
s 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 Addr
s 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.
Addr
s may be converted to RegVal
s and vice versa:
let value = RegVal::from_u32(0x2000_0000);
let addr: Addr = value.into();
let new_value = (addr + 0x0a).into();
Addr
s can also be compared with <
, <=
, etc. This is useful for certain implementations of
Memory
which would like to store Addr
s in
BTreeMap
s.
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§
Trait Implementations§
source§impl AddAssign<RegVal> for Addr
impl AddAssign<RegVal> for Addr
source§fn add_assign(&mut self, offset: RegVal)
fn add_assign(&mut self, offset: RegVal)
+=
operation. Read moresource§impl AddAssign<i32> for Addr
impl AddAssign<i32> for Addr
source§fn add_assign(&mut self, offset: i32)
fn add_assign(&mut self, offset: i32)
+=
operation. Read moresource§impl AddAssign<u32> for Addr
impl AddAssign<u32> for Addr
source§fn add_assign(&mut self, offset: u32)
fn add_assign(&mut self, offset: u32)
+=
operation. Read moresource§impl AddAssign<usize> for Addr
impl AddAssign<usize> for Addr
source§fn add_assign(&mut self, offset: usize)
fn add_assign(&mut self, offset: usize)
+=
operation. Read moresource§impl Ord for Addr
impl Ord for Addr
source§impl PartialEq for Addr
impl PartialEq for Addr
source§impl PartialOrd for Addr
impl PartialOrd for Addr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more