libriscv-0.1.0.0: A versatile, flexible and executable formal model for the RISC-V architecture.
Safe HaskellSafe-Inferred
LanguageHaskell2010

LibRISCV.Effects.Operations.Default.Machine.Memory

Description

Provides an implementatio of a byte-addressable memory, intended for internal usage in interpreters for the Operations effect.

Synopsis

Documentation

data Memory t a Source #

Representation of a byte-addressable memory. The type is parameterized over an array implementation (such as IOUArray) and a generic value type (used to represent instruction operands).

class HalfStorage halfType byteType where Source #

Since the memory is byte-addressable it requires converting values of a larger size to bytes. This type class is responsible for a conversion of 16-bit values (halfs). That is, it converts halfs to bytes (and vice versa) in little endian.

Methods

toHalf :: [byteType] -> halfType Source #

Convert a list of two bytes to a single half.

halfToBytes :: halfType -> [byteType] Source #

Convert a single half to a list of two bytes.

class WordStorage wordType byteType where Source #

Similar to HalfStorage but handles conversion of 32-bit values (words).

Methods

toWord :: [byteType] -> wordType Source #

Convert a list of four bytes to a single word.

wordToBytes :: wordType -> [byteType] Source #

Convert a single word to a list of four bytes.

mkMemory :: MArray t a IO => Address -> Word32 -> IO (Memory t a) Source #

Create a new memory of the given size starting at the given address.

memSize :: MArray t a IO => Memory t a -> IO Word32 Source #

Returns the size of the memory in bytes.

loadByte :: MArray t a IO => Memory t a -> Address -> IO a Source #

Load a single byte from memory at the given address.

loadHalf :: (MArray t a IO, HalfStorage b a) => Memory t a -> Address -> IO b Source #

Load a half (16-bit) from memory at the given address.

loadWord :: (MArray t a IO, WordStorage b a) => Memory t a -> Address -> IO b Source #

Load a word (32-bit) from memory at the given address.

storeByte :: MArray t a IO => Memory t a -> Address -> a -> IO () Source #

Store a single byte in memory.

storeHalf :: (MArray t a IO, HalfStorage b a) => Memory t a -> Address -> b -> IO () Source #

Store a half (16-bit) in memory.

storeWord :: (MArray t a IO, WordStorage b a) => Memory t a -> Address -> b -> IO () Source #

Store a word (32-bit) in memory.

storeByteString :: MArray t a IO => (Word8 -> a) -> Memory t a -> Address -> ByteString -> IO () Source #

Write a ByteString to memory in little endian byteorder. Expects a function to convert single bytes (Word8) to the chosen value representation, a Memory, as well the Address where the string should be stored and the ByteString itself.

mkWord :: [Word8] -> Word32 Source #

Converts a list of bytes to a Word32 in little endian.

mkBytes :: Word32 -> [Word8] Source #

Split a 32-bit word into four octets in little endian.