TEMU  4.4
The Terma Emulator
Memory.h File Reference
#include "temu-c/Support/Attributes.h"
#include "temu-c/Support/Objsys.h"
#include <stdint.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_IRInstruction
 
struct  temu_ExtIRInstruction
 
struct  temu_PDCIface
 

Macros

#define TEMU_MEMORY_SPACE_IFACE_TYPE   "temu::MemorySpaceIface"
 
#define TEMU_PDC_PSEUDO_UNKNOWN_INSTR   0
 
#define TEMU_PDC_PSEUDO_EOP   1
 
#define TEMU_PDC_PSEUDO_TRAMPOLINE   2
 
#define TEMU_PDC_PSEUDO_POST_DS_0   3
 
#define TEMU_PDC_PSEUDO_POST_DS_1   4
 
#define TEMU_PDC_PSEUDO_ATTRIB_CHECK   5
 
#define TEMU_PDC_PSEUDO_PROFILE   6
 
#define TEMU_PDC_PSEUDO_PRE_TRAMPOLINE   7
 
#define TEMU_PDC_PSEUDO_IDLE   8
 
#define TEMU_PDC_PSEUDO_SKIP   9
 
#define TEMU_PDC_PSEUDO_CALL   10
 
#define TEMU_PDC_PSEUDO_CALL_AND_SKIP   11
 
#define TEMU_PDC_PSEUDO_MULTIPAGE   12
 
#define TEMU_PDC_PSEUDO_OP_COUNT   13
 
#define TEMU_PDC_IFACE_TYPE   "PDCIface"
 

Typedefs

typedef enum temu_MemoryKind temu_MemoryKind
 
typedef enum temu_MemoryAttr temu_MemoryAttr
 Memory attribute enumeration. More...
 
typedef uint8_t temu_MemoryAttrs
 
typedef struct temu_MemAccessIface temu_MemAccessIface
 
typedef enum temu_MemoryStat temu_MemoryStat
 
typedef struct temu_MemorySpaceIface temu_MemorySpaceIface
 

Enumerations

enum  temu_MemoryKind {
  teMK_RAM = 0, teMK_ROM = 1, teMK_MMIO = 2, teMK_IO = 2,
  teMK_MemSpace = 4, teMK_Last = 4
}
 
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...
 
enum  temu_MemoryStat {
  teMS_IOReads, teMS_IOWrites, teMS_SelfModifyingCodeWrites, teMS_CodeWrites,
  teMS_LocksTaken, teMS_IOReadTime, teMS_IOWriteTime, teMS_LockTime
}
 

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_memoryReadData (void *obj, uint64_t addr, uint8_t *buff, unsigned unitSize, uint32_t size, unsigned flags)
 
TEMU_API int temu_memoryWriteData (void *obj, uint64_t addr, const uint8_t *buff, unsigned unitSize, uint32_t size, unsigned flags)
 
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 int temu_memoryMapNamedIface2 (void *Obj, uint64_t Addr, uint64_t Len, void *MemObj, const char *IfaceName, unsigned Idx, 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)
 
TEMU_API int temu_memoryReadPhys16 (void *Obj, uint64_t Addr, uint16_t *Word)
 
TEMU_API int temu_memoryReadPhys16Little (void *Obj, uint64_t Addr, uint16_t *Word)
 
TEMU_API int temu_memoryReadPhys32 (void *Obj, uint64_t Addr, uint32_t *Word)
 
TEMU_API int temu_memoryReadPhys32Little (void *Obj, uint64_t Addr, uint32_t *Word)
 
TEMU_API int temu_memoryWritePhys32 (void *Obj, uint64_t Addr, uint32_t Word)
 
TEMU_API int temu_memoryWritePhys32Little (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)
 
TEMU_API int temu_memoryInstallTrampoline (void *Obj, uint64_t Addr, void(*Tramp)(void *))
 
TEMU_API uint64_t temu_irToPhys (void *obj, uintptr_t ir)
 
TEMU_API uint64_t temu_irToPhysForCpu (void *obj, int cpu, uintptr_t ir)
 

Macro Definition Documentation

◆ TEMU_MEMORY_SPACE_IFACE_TYPE

#define TEMU_MEMORY_SPACE_IFACE_TYPE   "temu::MemorySpaceIface"

◆ TEMU_PDC_IFACE_TYPE

#define TEMU_PDC_IFACE_TYPE   "PDCIface"

◆ TEMU_PDC_PSEUDO_ATTRIB_CHECK

#define TEMU_PDC_PSEUDO_ATTRIB_CHECK   5

◆ TEMU_PDC_PSEUDO_CALL

#define TEMU_PDC_PSEUDO_CALL   10

◆ TEMU_PDC_PSEUDO_CALL_AND_SKIP

#define TEMU_PDC_PSEUDO_CALL_AND_SKIP   11

◆ TEMU_PDC_PSEUDO_EOP

#define TEMU_PDC_PSEUDO_EOP   1

◆ TEMU_PDC_PSEUDO_IDLE

#define TEMU_PDC_PSEUDO_IDLE   8

◆ TEMU_PDC_PSEUDO_MULTIPAGE

#define TEMU_PDC_PSEUDO_MULTIPAGE   12

◆ TEMU_PDC_PSEUDO_OP_COUNT

#define TEMU_PDC_PSEUDO_OP_COUNT   13

◆ TEMU_PDC_PSEUDO_POST_DS_0

#define TEMU_PDC_PSEUDO_POST_DS_0   3

◆ TEMU_PDC_PSEUDO_POST_DS_1

#define TEMU_PDC_PSEUDO_POST_DS_1   4

◆ TEMU_PDC_PSEUDO_PRE_TRAMPOLINE

#define TEMU_PDC_PSEUDO_PRE_TRAMPOLINE   7

◆ TEMU_PDC_PSEUDO_PROFILE

#define TEMU_PDC_PSEUDO_PROFILE   6

◆ TEMU_PDC_PSEUDO_SKIP

#define TEMU_PDC_PSEUDO_SKIP   9

◆ TEMU_PDC_PSEUDO_TRAMPOLINE

#define TEMU_PDC_PSEUDO_TRAMPOLINE   2

◆ TEMU_PDC_PSEUDO_UNKNOWN_INSTR

#define TEMU_PDC_PSEUDO_UNKNOWN_INSTR   0

Typedef Documentation

◆ temu_MemAccessIface

◆ temu_MemoryAttr

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.

◆ temu_MemoryAttrs

typedef uint8_t temu_MemoryAttrs

◆ temu_MemoryKind

◆ temu_MemorySpaceIface

◆ temu_MemoryStat

Enumeration Type Documentation

◆ temu_MemoryAttr

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.

◆ temu_MemoryKind

Enumerator
teMK_RAM 

Model is a RAM.

teMK_ROM 

Model is a ROM.

teMK_MMIO 

Alias for teMK_IO

teMK_IO 

Model is a normal IO device.

teMK_MemSpace 

Model is a memory space.

teMK_Last 

DO NOT USE.

◆ temu_MemoryStat

Enumerator
teMS_IOReads 
teMS_IOWrites 
teMS_SelfModifyingCodeWrites 
teMS_CodeWrites 
teMS_LocksTaken 
teMS_IOReadTime 
teMS_IOWriteTime 
teMS_LockTime 

Function Documentation

◆ TEMU_IFACE_REFERENCE_TYPE() [1/2]

TEMU_IFACE_REFERENCE_TYPE ( temu_MemorySpace  )

◆ TEMU_IFACE_REFERENCE_TYPE() [2/2]

TEMU_IFACE_REFERENCE_TYPE ( temu_PDC  )

◆ temu_irToPhys()

TEMU_API uint64_t temu_irToPhys ( void *  obj,
uintptr_t  ir 
)

◆ temu_irToPhysForCpu()

TEMU_API uint64_t temu_irToPhysForCpu ( void *  obj,
int  cpu,
uintptr_t  ir 
)

◆ temu_memoryClearAttr()

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_memoryGetAttrs()

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_memoryInstallTrampoline()

TEMU_API int temu_memoryInstallTrampoline ( void *  Obj,
uint64_t  Addr,
void(*)(void *)  Tramp 
)

Install trampoline function in PDC cache

Parameters
ObjMemory space
AddrPhysical address
TrampTrampoline function, takes CPU pointer as first argument.
Returns
0 on success

◆ temu_memoryMap()

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_memoryMapNamedIface()

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_memoryMapNamedIface2()

TEMU_API int temu_memoryMapNamedIface2 ( void *  Obj,
uint64_t  Addr,
uint64_t  Len,
void *  MemObj,
const char *  IfaceName,
unsigned  Idx,
uint32_t  Flags 
)

◆ temu_memoryRead()

TEMU_API int temu_memoryRead ( void *  mem,
uint8_t *  buff,
uint64_t  addr,
uint32_t  size,
int  swap 
)

Read block of data via memory block transfer interfaces

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_memoryReadData()

TEMU_API int temu_memoryReadData ( void *  obj,
uint64_t  addr,
uint8_t *  buff,
unsigned  unitSize,
uint32_t  size,
unsigned  flags 
)

Read block of data via large memory transactions.

Parameters
objMemory space object
addrPhysical address inside memory space
buffData buffer
unitSizeLog size of transaction unit size (0 = u8, 1 = u16, 2 = u32, 3 = u64)
sizeNumber of units to transfer
flagsMemory transaction flags (e.g. TEMU_MT_LITTLE_ENDIAN)
Returns
Negative on failures. Other values indicate success.

◆ temu_memoryReadPhys16()

TEMU_API int temu_memoryReadPhys16 ( void *  Obj,
uint64_t  Addr,
uint16_t *  Word 
)

Issue a big endian memory read transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word16 bit word that is read
Returns
0 on success, other values imply failure and will not update the word.

◆ temu_memoryReadPhys16Little()

TEMU_API int temu_memoryReadPhys16Little ( void *  Obj,
uint64_t  Addr,
uint16_t *  Word 
)

Issue a little endian memory read transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word16 bit word that is read
Returns
0 on success, other values imply failure and will not update the word.

◆ temu_memoryReadPhys32()

TEMU_API int temu_memoryReadPhys32 ( void *  Obj,
uint64_t  Addr,
uint32_t *  Word 
)

Issue a big endian 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_memoryReadPhys32Little()

TEMU_API int temu_memoryReadPhys32Little ( void *  Obj,
uint64_t  Addr,
uint32_t *  Word 
)

Issue a little endian 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_memorySetAttr()

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_memoryWrite()

TEMU_API int temu_memoryWrite ( void *  mem,
uint64_t  addr,
uint8_t *  buff,
uint32_t  size,
int  swap 
)

Write block of data via memory block transfer interfaces

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_memoryWriteData()

TEMU_API int temu_memoryWriteData ( void *  obj,
uint64_t  addr,
const uint8_t *  buff,
unsigned  unitSize,
uint32_t  size,
unsigned  flags 
)

Write block of data via large memory transactions.

Parameters
objMemory space object
addrPhysical address inside memory space
buffData buffer
unitSizeLog size of transaction unit size (0 = u8, 1 = u16, 2 = u32, 3 = u64)
sizeNumber of units to transfer
flagsMemory transaction flags (e.g. TEMU_MT_LITTLE_ENDIAN)
Returns
Negative on failures. Other values indicate success.

◆ temu_memoryWritePhys32()

TEMU_API int temu_memoryWritePhys32 ( void *  Obj,
uint64_t  Addr,
uint32_t  Word 
)

Issue a big endian memory write transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word32 bit word to write
Returns
0 on success

◆ temu_memoryWritePhys32Little()

TEMU_API int temu_memoryWritePhys32Little ( void *  Obj,
uint64_t  Addr,
uint32_t  Word 
)

Issue a little endian memory write transaction (without initiator)

Parameters
ObjMemory space
AddrPhysical address
Word32 bit word to write
Returns
0 on success

◆ temu_normaliseRead16()

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_normaliseRead32()

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_normaliseWrite16()

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_normaliseWrite32()

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