TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Memory.h File Reference
#include <stdint.h>
#include "temu-c/Support/Attributes.h"
#include "temu-c/Support/Objsys.h"
Include dependency graph for Memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  temu_MemorySpaceIface
 
struct  temu_PDCIface
 

Macros

#define TEMU_MEMORY_SPACE_IFACE_TYPE   "MemorySpaceIface"
 
#define TEMU_PDC_IFACE_TYPE   "PDCIface"
 

Typedefs

typedef uint8_t temu_MemoryAttrs
 
typedef struct
temu_MemorySpaceIface 
temu_MemorySpaceIface
 

Enumerations

enum  temu_MemoryAttr {
  teMA_Break = 1, teMA_WatchRead = 1 << 1, teMA_WatchWrite = 1 << 2, teMA_Upset = 1 << 3,
  teMA_Faulty = 1 << 4, teMA_User1 = 1 << 5, teMA_User2 = 1 << 6, teMA_User3 = 1 << 7
}
 Memory attribute enumeration. More...
 

Functions

 TEMU_IFACE_REFERENCE_TYPE (temu_MemorySpace)
 
 TEMU_IFACE_REFERENCE_TYPE (temu_PDC)
 
TEMU_API int temu_memoryRead (void *mem, uint8_t *buff, uint64_t addr, uint32_t size, int swap)
 
TEMU_API int temu_memoryWrite (void *mem, uint64_t addr, uint8_t *buff, uint32_t size, int swap)
 
TEMU_API int temu_memoryMap (void *Obj, uint64_t Addr, uint64_t Len, void *MemObj, uint32_t Flags)
 
TEMU_API int temu_memoryMapNamedIface (void *Obj, uint64_t Addr, uint64_t Len, void *MemObj, const char *IfaceName, uint32_t Flags)
 
TEMU_API void temu_memorySetAttr (void *Obj, uint64_t Addr, uint64_t Len, temu_MemoryAttr Attr)
 
TEMU_API void temu_memoryClearAttr (void *Obj, uint64_t Addr, uint64_t Len, temu_MemoryAttr Attr)
 
TEMU_API temu_MemoryAttrs temu_memoryGetAttrs (void *Obj, uint64_t Addr)
 Get memory attributes for address. More...
 
TEMU_API int temu_memoryReadPhys32 (void *Obj, uint64_t Addr, uint32_t *Word)
 
TEMU_API int temu_memoryWritePhys32 (void *Obj, uint64_t Addr, uint32_t Word)
 
TEMU_API uint32_t temu_normaliseWrite32 (uint32_t OldVal, uint32_t NewVal, int Sz, int Off)
 
TEMU_API uint32_t temu_normaliseRead32 (uint32_t Value, int Sz, int Off)
 
TEMU_API uint16_t temu_normaliseRead16 (uint16_t Value, int Sz, int Off)
 
TEMU_API uint16_t temu_normaliseWrite16 (uint16_t OldVal, uint16_t NewVal, int Sz, int Off)
 

Macro Definition Documentation

#define TEMU_MEMORY_SPACE_IFACE_TYPE   "MemorySpaceIface"

Definition at line 61 of file Memory.h.

#define TEMU_PDC_IFACE_TYPE   "PDCIface"

Definition at line 72 of file Memory.h.

Typedef Documentation

typedef uint8_t temu_MemoryAttrs

Definition at line 44 of file Memory.h.

Enumeration Type Documentation

Memory attribute enumeration.

The emulator provides 5 standard attributes, and 3 user defined ones. The attributes are set in the memory space (not the memory models), so it is possible to set a watch point on memory mapped devices. When an attribute is set on a page, that page will get a shadow attribute page (same size as the page), enabling attributes to be set on a per byte level.

Attributes are only checked on the address being accessed, the transaction size is not taken into account.

Enumerator
teMA_Break 

Breakpoint set.

teMA_WatchRead 

Read watchpoint set.

teMA_WatchWrite 

Write watchpoint set.

teMA_Upset 

Single event upset.

teMA_Faulty 

Multiple event upset / uncorrectable.

teMA_User1 

User definable.

teMA_User2 

User definable.

teMA_User3 

User definable.

Definition at line 33 of file Memory.h.

Function Documentation

TEMU_IFACE_REFERENCE_TYPE ( temu_MemorySpace  )
TEMU_IFACE_REFERENCE_TYPE ( temu_PDC  )
TEMU_API void temu_memoryClearAttr ( void *  Obj,
uint64_t  Addr,
uint64_t  Len,
temu_MemoryAttr  Attr 
)

Clears an attribute on the given memory range

Parameters
ObjMemory space object
AddrPhysical address of start
LenLength of memory range
AttrAttribute to clear
TEMU_API temu_MemoryAttrs temu_memoryGetAttrs ( void *  Obj,
uint64_t  Addr 
)

Get memory attributes for address.

Parameters
ObjMemory space
AddrPhysical addres
Returns
Memory attributes for the address
TEMU_API int temu_memoryMap ( void *  Obj,
uint64_t  Addr,
uint64_t  Len,
void *  MemObj,
uint32_t  Flags 
)

temu_memoryMap Maps an object into a memory space. The object must have an interface named MemAccessIface, of the type defined as TEMU_MEM_ACCESS_IFACE_TYPE

Parameters
Objis the memory space object
Addrthe physical address
Lenthe length in bytes
MemObjis the object that is mapped into the memory space it needs to be of a class that follows the rules above
Flagsare flags that are copied into the memory transaction object's flag field when a transaction reaches an object
Returns
Zero on success
TEMU_API int temu_memoryMapNamedIface ( void *  Obj,
uint64_t  Addr,
uint64_t  Len,
void *  MemObj,
const char *  IfaceName,
uint32_t  Flags 
)

temu_memoryMapNamedIface Maps an object into a memory space using the named memory access interface. The interface named by IfaceName must be of the type TEMU_MEM_ACCESS_IFACE_TYPE

Parameters
Objis the memory space object
Addrthe physical address
Lenthe length in bytes
MemObjis the object that is mapped into the memory space it needs to be of a class that follows the rules above
IfaceNameName of the memory access interface
Flagsare flags that are copied into the memory transaction object's flag field when a transaction reaches an object
Returns
Zero on success
TEMU_API int temu_memoryRead ( void *  mem,
uint8_t *  buff,
uint64_t  addr,
uint32_t  size,
int  swap 
)

temu_memoryRead TODO

Parameters
memPointer to memory space object
buffThe buffer to which the memory should be stored
addrThe address of the memory block to be read
sizeThe size to be read
swapsetting this to 0 indicates reading a byte array, 1 a uint16 array, 2 a uint32 array and 3 a uint64 array
Returns
Negative on failures. Other values indicate success. The convention is to return the number of bytes read which should be == size.
TEMU_API int temu_memoryReadPhys32 ( void *  Obj,
uint64_t  Addr,
uint32_t *  Word 
)

Issue a memory read transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word32 bit word that is read
Returns
0 on success, other values imply failure and will not update the word.
TEMU_API void temu_memorySetAttr ( void *  Obj,
uint64_t  Addr,
uint64_t  Len,
temu_MemoryAttr  Attr 
)

Sets an attribute on the given memory range

Parameters
ObjMemory space object
AddrPhysical address of start
LenLength of memory range
AttrAttribute to set
TEMU_API int temu_memoryWrite ( void *  mem,
uint64_t  addr,
uint8_t *  buff,
uint32_t  size,
int  swap 
)

temu_memoryWrite TODO

Parameters
memPointer to memory space object
buffThe buffer to which the memory should be stored
addrThe address, at which the write should be done
sizeThe size to be read
swapNegative on failures. Other values indicate success.
Returns
Negative on failure. Other values indicate success. The convention is to return the number of bytes written, which should be == size.
TEMU_API int temu_memoryWritePhys32 ( void *  Obj,
uint64_t  Addr,
uint32_t  Word 
)

Issue a memory write transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word32 bit word to write
Returns
0 on success
TEMU_API uint16_t temu_normaliseRead16 ( uint16_t  Value,
int  Sz,
int  Off 
)

Normalise a value for reads where only 16 bit transactions are supported by the device model, but the target is allowed to read non-16 bit quantities.

Given a 32 bit register value, the function extracts the bits from it that was actually requested.

Parameters
ValueRegister value
SzSize in log number of bytes (0 or 1)
OffOffset in bytes within the 32 bit word of the transaction (0 or 2)
TEMU_API uint32_t temu_normaliseRead32 ( uint32_t  Value,
int  Sz,
int  Off 
)

Normalise a value for reads where only 32 bit transactions are supported by the device model, but the target is allowed to read non-32 bit quantities.

Given a 32 bit register value, the function extracts the bits from it that was actually requested.

Parameters
ValueRegister value
SzSize in log number of bytes (0, 1, or 2)
OffOffset in bytes within the 32 bit word of the transaction (0-3)
TEMU_API uint16_t temu_normaliseWrite16 ( uint16_t  OldVal,
uint16_t  NewVal,
int  Sz,
int  Off 
)

Normalise a value for writes where only 16 bit transactions are supported by the device model, but the target is allowed to write non-16 bit quantity. The function mixes the old register value with the new one based on the size and offset parameter. The problem exists because the memory access interface has a value entry, which always ends up in the lower bits, so if we write to the higher bits in in a 16 bit register, then by just forwarding the the value as is to the write handler, will result in a write of the lower bits and a clear of the upper bits (for a store unsigned).

Thus a normalisation is neded where we mix the written word with the old bits. So for transaction size of 8, and an offset of8, the resulting word is (old & 0x00ff) | (new << 8)

Parameters
OldValOld regiseter value.
NewValContent in memory transaction (new value).
SzSize in log number of bytes
OffOffset in bytes within the 16 bit word of the transaction.
TEMU_API uint32_t temu_normaliseWrite32 ( uint32_t  OldVal,
uint32_t  NewVal,
int  Sz,
int  Off 
)

Normalise a value for writes where only 32 bit transactions are supported by the device model, but the target is allowed to write non-32 bit quantity. The function mixes the old register value with the new one based on the size and offset parameter. The problem exists because the memory access interface has a value entry, which always ends up in the lower bits, so if we write to the higher bits in in a 32 bit register, then by just forwarding the the value as is to the write handler, will result in a write of the lower bits and a clear of the upper bits (for a store unsigned).

Thus a normalisation is neded where we mix the written word with the old bits. So for transaction size of 16, and an offset of 16, the resulting word is (old & 0x0000ffff) | (new << 16)

Parameters
OldValOld regiseter value.
NewValContent in memory transaction (new value).
SzSize in log number of bytes
OffOffset in bytes within the 32 bit word of the transaction.