Struct riscy::memory::PagedMemory

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

PagedMemory is the implementation of the Memory interfaced used by the riscy binary.

Whenever an address is first accessed, it will allocate a 4KiB page containing that address. The pages are stored in a BTreeMap which making finding the correct page fast and efficient. Each page is represented by contiguous block of memory.

The full 32-bit address space of a RISC-V machine is 4GiB in size. Using on-demand pages like this means that the host system usually only allocates a bit more memory than it actually uses.

Once a page is allocated, it is never de-allocated.

When reading from uninitilized memory, PagedMemory will return a value of 0x00 for that byte. This is unrealistic in physical memory, where you get whatever junk the operating system or the hardware had left over. However, getting zeroed-out memory makes it easier to debug when there is a problem.

Implementations§

source§

impl PagedMemory

source

pub fn new() -> PagedMemory

Create a new PagedMemory with no allocated pages.

Trait Implementations§

source§

impl Debug for PagedMemory

source§

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

Formats the value using the given formatter. Read more
source§

impl Memory for PagedMemory

source§

fn store_byte(&mut self, addr: Addr, value: u8)

source§

fn load_byte(&self, addr: Addr) -> u8

source§

fn load_halfword(&self, addr: Addr) -> u16

source§

fn load_word(&self, addr: Addr) -> u32

source§

fn store_halfword(&mut self, addr: Addr, value: u16)

source§

fn store_word(&mut self, addr: Addr, value: u32)

source§

fn memcpy(&mut self, base_addr: Addr, buf: &[u8])

Auto Trait Implementations§

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, 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.