3.2 Device API Data Types 3.4 Obsolete Device API Types and Functions
API Reference Manual  /  3 Device API  / 

3.3 Device API Functions

Attribute Values

SIM_alloc_attr_dict()

NAME
SIM_alloc_attr_dict — create empty attribute dictionary
SYNOPSIS
attr_value_t
SIM_alloc_attr_dict(unsigned length);

DESCRIPTION
Returns an attr_value_t of type dict with size len. The dictionary elements are initialized to invalid values.
EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_alloc_attr_list

SIM_alloc_attr_list()

NAME
SIM_alloc_attr_list — create uninitialized attribute list
SYNOPSIS
attr_value_t
SIM_alloc_attr_list(unsigned length);

DESCRIPTION
Returns an attr_value_t of type list with size length. The list elements are initialized to invalid values.
EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_make_attr_list

SIM_attr_copy()

NAME
SIM_attr_copy — copy attribute value
SYNOPSIS
attr_value_t
SIM_attr_copy(attr_value_t val);

DESCRIPTION
Return a deep copy of val. The caller obtains ownership of the copy and needs to free it after use; the argument is not modified.

This function is not available from Python.

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_attr_free

SIM_attr_dict_resize()

NAME
SIM_attr_dict_resize — resize dict attribute value
SYNOPSIS
void
SIM_attr_dict_resize(attr_value_t *NOTNULL attr, unsigned newsize);

DESCRIPTION
Resize attr, which must be of dict type, to newsize elements. New elements are marked invalid. Dropped elements are freed.
EXECUTION CONTEXT
Cell Context

SIM_attr_dict_set_item()

NAME
SIM_attr_dict_set_item — set dict attribute element
SYNOPSIS
void
SIM_attr_dict_set_item(attr_value_t *NOTNULL attr, unsigned index,
                       attr_value_t key, attr_value_t value);

DESCRIPTION
Set the element numbered index of the dict attr to key and value. The previous key and value at that position are freed. The ownership for key and value is transferred from the caller to attr. The key must be of integer, string or object type.
EXECUTION CONTEXT
Cell Context

SIM_attr_free()

NAME
SIM_attr_free, SIM_free_attribute — free attribute
SYNOPSIS
void
SIM_attr_free(attr_value_t *NOTNULL value);

void
SIM_free_attribute(attr_value_t value);

DESCRIPTION
Free the memory allocation used by the value pointed to by value. For values of list or dict type, this recursively frees all contents; for string or data values, the allocation containing the payload is freed. It is an error to use the value or any sub-part of it after it has been freed.

SIM_attr_free is the preferred call because it changes the type of the argument variable to Invalid, preventing accidental use after freeing. SIM_free_attribute only differs in how the argument is passed, but cannot change the argument variable as it is passed by value.

Note: These functions are not available in Python; memory allocation is managed automatically there.
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_attr_integer()

NAME
SIM_attr_integer, SIM_attr_boolean, SIM_attr_string, SIM_attr_string_detach, SIM_attr_floating, SIM_attr_object, SIM_attr_object_or_nil, SIM_attr_data_size, SIM_attr_data, SIM_attr_list_size, SIM_attr_list_item, SIM_attr_list, SIM_attr_dict_size, SIM_attr_dict_key, SIM_attr_dict_value — extract values stored in attr_value_t values
SYNOPSIS
FORCE_INLINE int64
SIM_attr_integer(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_boolean(attr_value_t attr);

FORCE_INLINE const char *
SIM_attr_string(attr_value_t attr);

FORCE_INLINE char *
SIM_attr_string_detach(attr_value_t *attr);

FORCE_INLINE double
SIM_attr_floating(attr_value_t attr);

FORCE_INLINE conf_object_t *
SIM_attr_object(attr_value_t attr);

FORCE_INLINE conf_object_t *
SIM_attr_object_or_nil(attr_value_t attr);

FORCE_INLINE unsigned
SIM_attr_data_size(attr_value_t attr);

FORCE_INLINE const uint8 *
SIM_attr_data(attr_value_t attr);

FORCE_INLINE unsigned
SIM_attr_list_size(attr_value_t attr);

FORCE_INLINE attr_value_t
SIM_attr_list_item(attr_value_t attr, unsigned index);

FORCE_INLINE attr_value_t *
SIM_attr_list(attr_value_t attr);

FORCE_INLINE unsigned
SIM_attr_dict_size(attr_value_t attr);

FORCE_INLINE attr_value_t
SIM_attr_dict_key(attr_value_t attr, unsigned index);

FORCE_INLINE attr_value_t
SIM_attr_dict_value(attr_value_t attr, unsigned index);

DESCRIPTION
Extract a value encapsulated in attr. It is an error to call an accessor function with an attr of the wrong type.

SIM_attr_integer returns the integer attribute value modulo-reduced to the interval [−263,263−1]. (Converting the return value to uint64 gives the integer attribute value modulo-reduced to [0,264−1].)

SIM_attr_string, SIM_attr_data and SIM_attr_list return values owned by attr. Ownership is not transferred to the caller.

SIM_attr_string_detach returns the string in attr and changes the value pointed to by attr into a nil attribute. Ownership of the string is transferred to the caller.

SIM_attr_object_or_nil accepts an attr parameter of either object or nil type. In case of a nil attribute, the function returns NULL.

SIM_attr_list_size and SIM_attr_dict_size return the number of items in the list and key-value pairs in the dict respectively. SIM_attr_data_size returns the number of bytes in the data value.

SIM_attr_list_item returns the item at index. The index must be less than the number of items in the list. The item returned is still owned by attr. Ownership is not transferred to the caller.

SIM_attr_list returns a pointer directly into the internal array of the attribute value; it is mainly present as an optimisation. Use SIM_attr_list_item and SIM_attr_list_set_item for type-safety instead.

SIM_attr_dict_key and SIM_attr_dict_value return the key and value at index. The index must be less than the number of items in the dict. The value returned is still owned by attr. Ownership is not transferred to the caller.

EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_attr_is_integer()

NAME
SIM_attr_is_integer, SIM_attr_is_boolean, SIM_attr_is_string, SIM_attr_is_floating, SIM_attr_is_object, SIM_attr_is_invalid, SIM_attr_is_data, SIM_attr_is_list, SIM_attr_is_dict, SIM_attr_is_nil, SIM_attr_is_int64, SIM_attr_is_uint64attr_value_t type predicates
SYNOPSIS
FORCE_INLINE bool
SIM_attr_is_integer(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_boolean(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_string(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_floating(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_object(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_invalid(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_data(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_list(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_dict(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_nil(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_int64(attr_value_t attr);

FORCE_INLINE bool
SIM_attr_is_uint64(attr_value_t attr);

DESCRIPTION
Indicates whether the value stored in attr is of the specified type. SIM_attr_is_int64 and SIM_attr_is_uint64 additionally test whether the integer value would fit in the given C type.
EXECUTION CONTEXT
Cell Context

SIM_attr_list_resize()

NAME
SIM_attr_list_resize — resize list attribute value
SYNOPSIS
void
SIM_attr_list_resize(attr_value_t *NOTNULL attr, unsigned newsize);

DESCRIPTION
Resize attr, which must be of list type, to newsize elements. New elements are set to invalid value. Dropped elements are freed.
EXECUTION CONTEXT
Cell Context

SIM_attr_list_set_item()

NAME
SIM_attr_list_set_item — set list attribute element
SYNOPSIS
void
SIM_attr_list_set_item(attr_value_t *NOTNULL attr, unsigned index,
                       attr_value_t elem);

DESCRIPTION
Set the element numbered index of the list attr to elem. The previous value at that position is freed. The ownership for elem is transferred from the caller to attr.
EXECUTION CONTEXT
Cell Context

SIM_attr_scanf()

NAME
SIM_attr_scanf, SIM_ascanf — parse list attribute values
SYNOPSIS
bool
SIM_attr_scanf(attr_value_t *NOTNULL list, const char *NOTNULL fmt, ...);

bool
SIM_ascanf(attr_value_t *NOTNULL list,
           const char *NOTNULL fmt, ...) __attribute__((alias("SIM_attr_scanf")));

DESCRIPTION
Reads and converts entries in list according to the format string fmt. Returns true if all elements were successfully converted, false otherwise.

The characters in the format string mean:

format char argument type element must be
i int64 * integer
b int * boolean
f double * floating
s const char ** string
S const char ** string or nil
o conf_object_t ** object
O conf_object_t ** object or nil
l attr_value_t ** list
d attr_value_t ** data
a attr_value_t ** any except invalid

The fmt string may also include a period (.) at the end, taken to mean that more elements may follow. If the period is not present, the length of the list must equal the number of specified elements.

Converted values of type attr_value_t * and const char * are still owned by list.

SIM_ascanf is an alias of SIM_attr_scanf and will be deprecated.

EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_make_attr_boolean()

NAME
SIM_make_attr_boolean — make boolean attribute
SYNOPSIS
FORCE_INLINE attr_value_t
SIM_make_attr_boolean(bool b);

DESCRIPTION
Returns an attr_value_t of boolean type.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_data()

NAME
SIM_make_attr_data, SIM_make_attr_data_adopt — create raw data attribute
SYNOPSIS
attr_value_t
SIM_make_attr_data(size_t size, const void *data);

FORCE_INLINE attr_value_t
SIM_make_attr_data_adopt(size_t size, void *data);

DESCRIPTION
Returns an attr_value_t of type data using size and data for the binary data.

SIM_make_attr_data will make a copy of the argument data.

SIM_make_attr_data_adopt is mainly provided for compatibility; it will assume ownership of the argument data, which must have been allocated using one of the MM_MALLOC functions.

EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_make_attr_floating()

NAME
SIM_make_attr_floating — make floating point attribute
SYNOPSIS
FORCE_INLINE attr_value_t 
SIM_make_attr_floating(double d);

DESCRIPTION
Returns an attr_value_t of floating type with value d.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_int64()

NAME
SIM_make_attr_int64, SIM_make_attr_uint64 — make integer attribute
SYNOPSIS
FORCE_INLINE attr_value_t
SIM_make_attr_int64(int64 i);

FORCE_INLINE attr_value_t
SIM_make_attr_uint64(uint64 i);

DESCRIPTION
Returns an attr_value_t of integer type with value i.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_invalid()

NAME
SIM_make_attr_invalid — make invalid attribute
SYNOPSIS
FORCE_INLINE attr_value_t
SIM_make_attr_invalid(void);

DESCRIPTION
Returns an attr_value_t of invalid type.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_list()

NAME
SIM_make_attr_list, SIM_make_attr_list_vararg — make list attribute
SYNOPSIS
attr_value_t
SIM_make_attr_list(unsigned length, ...);

attr_value_t
SIM_make_attr_list_vararg(unsigned length, va_list va);

DESCRIPTION
Returns an attr_value_t of type list with size length. The list is filled with data from the arguments following, which should be of type attr_value_t.

This function must be called with exactly length+1 arguments. The attribute parameters should all be valid attributes; e.g., attributes of invalid type are not allowed. The length argument must be a constant expression.

The newly created list assumes ownership of the passed parameters, which therefore should not be freed.

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_alloc_attr_list

SIM_make_attr_nil()

NAME
SIM_make_attr_nil — make nil attribute
SYNOPSIS
FORCE_INLINE attr_value_t
SIM_make_attr_nil(void);

DESCRIPTION
Returns an attr_value_t of type nil.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_object()

NAME
SIM_make_attr_object — make object attribute
SYNOPSIS
FORCE_INLINE attr_value_t
SIM_make_attr_object(conf_object_t *obj);

DESCRIPTION
Returns an attr_value_t of object type with value obj. Returns a nil value if obj is NULL.
EXECUTION CONTEXT
Cell Context

SIM_make_attr_string()

NAME
SIM_make_attr_string, SIM_make_attr_string_adopt — make string attribute
SYNOPSIS
attr_value_t
SIM_make_attr_string(const char *str);

FORCE_INLINE attr_value_t
SIM_make_attr_string_adopt(char *str);

DESCRIPTION
Returns an attr_value_t of type string with value str. Returns Nil if str is NULL.

SIM_make_attr_string will make a copy of the argument string.

SIM_make_attr_string_adopt is mainly provided for compatibility; it will assume ownership of the argument string, which must have been allocated using one the MM_MALLOC functions.

EXECUTION CONTEXT
All contexts (including Threaded Context)

Configuration

SIM_attribute_error()

NAME
SIM_attribute_error, SIM_c_attribute_error — specify reason for attribute error
SYNOPSIS
void
SIM_attribute_error(const char *NOTNULL msg);

void
SIM_c_attribute_error(const char *NOTNULL msg, ...);

DESCRIPTION
When used inside an attribute set_attr/get_attr method, indicates why it failed to set or retrieve the attribute. This function only serves to give an informative message to the user. The object or attribute names need not be mentioned in the msg argument; Simics will supply this automatically. SIM_c_attribute_error is similar but the msg argument and those following it are used for string formatting in the same way as in the standard sprintf function. This function is not available from Python.

The error message supplied will be attached to any frontend exception generated by the attribute access.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_attribute, SIM_get_attribute, SIM_set_attribute

SIM_class_port()

NAME
SIM_class_port — check if class has specified port object
SYNOPSIS
conf_class_t *
SIM_class_port(const conf_class_t *NOTNULL cls, const char *NOTNULL name);

DESCRIPTION
Returns the class of objects on the port named name, or NULL if no such port is registered.
SEE ALSO
SIM_register_port, SIM_register_simple_port
EXECUTION CONTEXT
Cell Context

SIM_copy_class()

NAME
SIM_copy_class — create a copy of an existing class
SYNOPSIS
conf_class_t *
SIM_copy_class(const char *NOTNULL name, const conf_class_t *NOTNULL src_cls,
               const char *desc);

DESCRIPTION
This function creates a copy of the class src_class named name.

Additional attributes and interfaces can be registered on the newly created class.

The new class is described by desc unless this parameter is NULL which means that the original class description should be used.

RETURN VALUE
The newly created class is returned.
SEE ALSO
SIM_extend_class, SIM_create_class
EXECUTION CONTEXT
Global Context

SIM_create_class()

NAME
SIM_create_class — create class
SYNOPSIS
conf_class_t *
SIM_create_class(const char *NOTNULL name,
                 const class_info_t *NOTNULL class_info);

DESCRIPTION
This function creates a new class that can be instantiated by calling the SIM_create_object function. It is a replacement for SIM_register_class and should be used in all new code.

The name can contain upper and lower case ASCII letters, hyphens, underscores, and digits. It must not begin with a digit or a hyphen and must not end with a hyphen.

class_info may be freed when the function has returned.

typedef enum {
        Sim_Class_Kind_Vanilla = 0, /* object is saved at checkpoints */
        Sim_Class_Kind_Session = 1, /* object is saved as part of a
                                     * session only */
        Sim_Class_Kind_Pseudo = 2,  /* object is never saved */

        Sim_Class_Kind_Extension = 3, /* extension class
                                         (see SIM_extend_class) */
} class_kind_t;

typedef struct class_info {
        conf_object_t *(*alloc)(conf_class_t *cls);
        lang_void *(*init)(conf_object_t *obj);
        void (*finalize)(conf_object_t *obj);
        void (*objects_finalized)(conf_object_t *obj);

        void (*deinit)(conf_object_t *obj);
        void (*dealloc)(conf_object_t *obj);

        const char           *description;
        const char           *short_desc;
        class_kind_t          kind;
} class_info_t;

RETURN VALUE
Class structure, or NULL on error.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_register_class_alias, class_info_t

SIM_ensure_partial_attr_order()

NAME
SIM_ensure_partial_attr_order — ensure attribute order
SYNOPSIS
void
SIM_ensure_partial_attr_order(conf_class_t *NOTNULL cls,
                              const char *NOTNULL before,
                              const char *NOTNULL after);

DESCRIPTION
Attribute initialization order is guaranteed to be identical to the order in which the attributes were registered. In some cases a particular order is required in order for a model to work correctly.

This function checks the registration order of the attributes before and after in the class cls. If before is not registered before after, or if at least one of the two are not registered at all, an ASSERT is triggered.

Use this function to ensure that e.g. code refactoring does not break a required attribute order.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_attribute

SIM_extend_class()

NAME
SIM_extend_class — extend class with contents from an extension class
SYNOPSIS
void
SIM_extend_class(conf_class_t *NOTNULL cls, conf_class_t *NOTNULL ext);

DESCRIPTION
The function extends the class cls with attributes, interfaces, port objects and port interfaces defined by the extension class ext.

The extension class must be of the type Sim_Class_Kind_Extension and must not define any attributes or interfaces which have already been defined by the class being augmented.

Besides normal object initialization, the init_object method for the extension class, will be called when cls is instantiated. The pointer returned by init_object can be retrieved using SIM_extension_data. The init_object method may return NULL if no private data pointer is needed; this does not signify an error condition for extension classes.

The finalize_instance method defined by the extension class will be called before the finalize_instance method is called for the class being extended.

The SIM_extension_class function is intended to be used to extend a class with generic functionality, common to multiple classes.

SEE ALSO
SIM_create_class, SIM_register_class, SIM_extension_data
EXECUTION CONTEXT
Global Context

SIM_extension_data()

NAME
SIM_extension_data — get class extension data
SYNOPSIS
void *
SIM_extension_data(conf_object_t *obj, conf_class_t *ext_cls);

DESCRIPTION
Returns the private data pointer of an object associated with the extension class ext_cls. The returned pointer is the value returned by the init_object method called for the extension class ext_cls.

The object obj must be an instance of a class which has been extended with the extension class ext_cls using the SIM_extend_class function.

SEE ALSO
SIM_object_data, SIM_register_class, SIM_extend_class
EXECUTION CONTEXT
Cell Context

SIM_get_class()

NAME
SIM_get_class — get class
SYNOPSIS
conf_class_t *
SIM_get_class(const char *NOTNULL name);

DESCRIPTION
Returns the configuration class called name.

If it finds no class called name, SIM_get_class will load a module implementing that class, if any can be found, and return the newly created class.

Note that loading a module can not be done during the simulation execution: in that case, SIM_get_class will trigger an error instead. If you encounter this problem, a simple work-around is to make sure that all necessary modules are loaded before starting the execution.

RETURN VALUE
Opaque pointer referencing the class, or NULL if not found.
EXCEPTIONS
SimExc_General Thrown if the class has not been registered.

EXECUTION CONTEXT
Cell Context, except when loading a module.
SEE ALSO
SIM_get_class_name

SIM_get_class_data()

NAME
SIM_get_class_data — get class data
SYNOPSIS
lang_void *
SIM_get_class_data(conf_class_t *cls);

DESCRIPTION
Obtain the class data that was set using SIM_set_class_data. This can be called at any time during the object initialisation process.
SEE ALSO
SIM_set_class_data
EXECUTION CONTEXT
Cell Context

SIM_get_class_name()

NAME
SIM_get_class_name — get class name
SYNOPSIS
const char *
SIM_get_class_name(const conf_class_t *NOTNULL class_data);

DESCRIPTION
Returns the name of the class. Simics retains ownership of the returned string; it must not be modified or freed by the caller.

In Python, the name of an object's class is available via the classname attribute:

obj.classname

.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_get_class

SIM_get_interface()

NAME
SIM_get_interface, SIM_c_get_interface, SIM_get_class_interface, SIM_c_get_class_interface, SIM_get_port_interface, SIM_c_get_port_interface, SIM_get_class_port_interface, SIM_c_get_class_port_interface — get interface
SYNOPSIS
const void *
SIM_get_interface(const conf_object_t *NOTNULL obj, const char *NOTNULL name);

const void *
SIM_c_get_interface(const conf_object_t *NOTNULL obj, const char *NOTNULL name);

const void *
SIM_get_class_interface(const conf_class_t *NOTNULL cls, 
                        const char *NOTNULL name);

const void *
SIM_c_get_class_interface(const conf_class_t *NOTNULL cls, 
                          const char *NOTNULL name);

const void *
SIM_get_port_interface(const conf_object_t *NOTNULL obj, 
                       const char *NOTNULL name, const char *portname);

const void *
SIM_c_get_port_interface(const conf_object_t *NOTNULL obj, 
                         const char *NOTNULL name, 
                         const char *portname);

const void *
SIM_get_class_port_interface(const conf_class_t *NOTNULL cls,
                             const char *NOTNULL name, 
                             const char *portname);

const void *
SIM_c_get_class_port_interface(const conf_class_t *NOTNULL cls,
                               const char *NOTNULL name, 
                               const char *portname);

DESCRIPTION
Get the interface with name name from object obj. Returns NULL, and raises an exception if obj does not implement the interface.

SIM_get_port_interface returns a port interface instance as registered with SIM_register_port_interface. The portname selects a particular implementation of the interface by obj's class. If no port name is supplied, the function behaves as SIM_get_interface.

SIM_get_class_interface and SIM_get_class_port_interface are similar but return the interface for a class instead of an object.

SIM_c_get_interface, SIM_c_get_port_interface, SIM_c_get_class_interface and SIM_c_get_class_port_interface are similar to their respective counterparts but never raise an exception, nor do they accept dashes inside name or portname instead of underscores.

The SIM_C_GET_INTERFACE macro is a useful type-safe replacement for SIM_c_get_interface. The macro takes an object and the name of the interface without quotes. Compare the three forms:

SIM_c_get_interface(obj, PCI_DEVICE_INTERFACE);
SIM_c_get_interface(obj, "pci_device");
SIM_C_GET_INTERFACE(obj, pci_device);
   

The data the result points to is owned by Simics. The caller must not deallocate or modify it.

In Python, there is usually no need to use these functions since Simics objects' interfaces are available via the iface attribute. Here is sample Python code calling the signal_raise method of the object's signal interface:

obj.iface.signal.signal_raise()

In a similar way one can call interfaces of an object's port objects. Here is a respective example where an object obj with a port object obj.port.reset has a signal interface:

obj.port.reset.iface.signal.signal_raise()

Port interfaces - interfaces that are registered with SIM_register_port_interface and are considered legacy - are also directly accessible in Python. Here is sample code calling the signal_raise method of the signal interface from the object's RESET port:

obj.ports.RESET.signal.signal_raise()

In order to check if a Simics object implements an interface the following Python code can be used:

if hasattr(obj.iface, "signal"):  # check whether obj has signal interface
    ...

RETURN VALUE
Pointer to interface, or NULL if not found.
EXCEPTIONS
SimExc_Lookup Thrown if the interface is not implemented by obj's class.

SimExc_General Thrown if the interface name is illegal.

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_register_interface

SIM_is_loading_micro_checkpoint()

NAME
SIM_is_loading_micro_checkpoint — check if micro checkpoint is being loaded
SYNOPSIS
bool
SIM_is_loading_micro_checkpoint(conf_object_t *obj);

DESCRIPTION
The function returns true if a persistent state or a micro checkpoint is being loaded. The return value is thus equal to the "SIM_object_is_configured(obj) && SIM_is_restoring_state(obj)" expression.
SEE ALSO
SIM_object_is_configured, SIM_is_restoring_state,
EXECUTION CONTEXT
Cell Context

SIM_is_restoring_state()

NAME
SIM_is_restoring_state — check if state restoring phase
SYNOPSIS
bool
SIM_is_restoring_state(conf_object_t *obj);

DESCRIPTION
Returns true if the configuration system is currently restoring the saved state for the object obj when reading a checkpoint, applying a persistent state or restoring a reverse execution bookmark.

SIM_is_restoring_state is typically used to prevent side effects in attribute set methods that only should run when the attribute is set manually, for example when hot plugging.

SIM_object_is_configured SIM_is_restoring_state
Creating object false false
Loading checkpoint false true
Loading persistent state true true
Loading micro-checkpoint (rev-exec) truetrue
Manual attribute access (hot plug) true false

LIMITATION: This function currently returns true for all objects in Simics while some state is being restored and not only for the affected objects.

SEE ALSO
SIM_object_is_configured
EXECUTION CONTEXT
Cell Context

SIM_marked_for_deletion()

NAME
SIM_marked_for_deletion — is object being deleted
SYNOPSIS
bool
SIM_marked_for_deletion(const conf_object_t *NOTNULL obj);

DESCRIPTION
Indicates if the given object is being deleted. This information can be useful by other objects that want to clean up their references.
RETURN VALUE
true if the object is being deleted.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_delete_objects

SIM_object_clock()

NAME
SIM_object_clock — get object clock
SYNOPSIS
conf_object_t *
SIM_object_clock(const conf_object_t *NOTNULL obj);

DESCRIPTION
Retrieve the default clock used by an object. This is set by the queue attribute and is used as time reference for the object.
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_object_data()

NAME
SIM_object_data — get object-specific data pointer
SYNOPSIS
lang_void *
SIM_object_data(conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the private data pointer of an object. This pointer is available to the class for storing instance-specific state.

It is initialised to the return value of the init (from class_info_t) method that is called during object creation. For classes created using the legacy SIM_register_class, the same functionality is provided by the init_object method .

For classes implemented in Python, the data (which is then a Python value) can also be accessed as obj.object_data.

For classes written in C, the preferred way to store instance-specific state is by co-allocation with the object's conf_object_t structure instead of using SIM_object_data. Such classes should define the alloc method in the class_info_t passed to SIM_create_class for allocating its instance data. For classes using the legacy SIM_register_class class registration function, they should define the alloc_object method in the class_data_t data structure.

SEE ALSO
SIM_create_class, SIM_register_class
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_object_id()

NAME
SIM_object_id — get object identifier
SYNOPSIS
const char *
SIM_object_id(const conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the unique identifier for an object. The identifier is a string that is guaranteed to be unique and will never change, even if the object moves to another hierarchical location.

The return value is a static string that should not be modified or freed by the caller.

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_object_name

SIM_object_is_configured()

NAME
SIM_object_is_configured, SIM_set_object_configured — get/set configured status
SYNOPSIS
bool
SIM_object_is_configured(const conf_object_t *NOTNULL obj);

void
SIM_set_object_configured(conf_object_t *NOTNULL obj);

DESCRIPTION
SIM_object_is_configured indicates whether obj is configured. SIM_set_object_configured sets the object as configured.

An object is configured once its finalize_instance method (post_init in DML) has completed, or SIM_set_object_configured has been called for it. Being configured indicates that the object is in a consistent state and is ready to be used by other objects.

SIM_set_object_configured is used to avoid circular dependencies between objects. It may only be called from the object's own finalize_instance method, when the object is known to be in a consistent state.

EXECUTION CONTEXT
SIM_object_is_configured: all contexts (including Threaded Context); SIM_set_object_configured: Global Context
SEE ALSO
SIM_require_object, SIM_register_class, SIM_is_restoring_state

SIM_object_name()

NAME
SIM_object_name — get object name
SYNOPSIS
const char *
SIM_object_name(const conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the name of an object. This name identifies the object uniquely, but may change if the object is moved to another hierarchical location.

The return value is a string, owned by obj, that should not be modified or freed by the caller.

In Python, an object's name is available via the name attribute:

obj.name

.

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_object_id

SIM_picosecond_clock()

NAME
SIM_picosecond_clock — get object picosecond clock
SYNOPSIS
conf_object_t *
SIM_picosecond_clock(conf_object_t *NOTNULL obj);

DESCRIPTION
Return the picosecond clock used by an object obj.

The returned clock uses a cycle period of exactly 1 ps. It has full picosecond resolution even if the processor (or clock) driving the simulation uses a lower resolution. An event posted at a particular picosecond triggers always at that precise time, without any rounding issues.

The returned object is the vtime.ps port object of the default clock for the object, and it implements the cycle_event interface.

The API functions SIM_event_post_cycle, SIM_event_post_time, SIM_event_find_next_cycle, SIM_event_cancel_time, and SIM_cycle_count can be used directly on the picosecond clock.

Note: The function SIM_time is currently not supported for the picosecond clock; it will return same value as if the function is invoked on the default clock.
Note: The picosecond clock will wrap around after roughly 200 days of virtual time (2^64 ps).
SEE ALSO
SIM_object_clock
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_register_attribute()

NAME
SIM_register_attribute, SIM_register_class_attribute, SIM_register_attribute_with_user_data, SIM_register_class_attribute_with_user_data — register attribute
SYNOPSIS
void
SIM_register_attribute(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(conf_object_t *),
        set_error_t (*set_attr)(conf_object_t *, attr_value_t *),
        attr_attr_t attr, const char *type, const char *desc);

void
SIM_register_class_attribute(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(conf_class_t *),
        set_error_t (*set_attr)(conf_class_t *, attr_value_t *),
        attr_attr_t attr, const char *type, const char *desc);

void
SIM_register_attribute_with_user_data(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(conf_object_t *, lang_void *),
        lang_void *user_data_get,
        set_error_t (*set_attr)(conf_object_t *, attr_value_t *, lang_void *),
        lang_void *user_data_set,
        attr_attr_t attr, const char *type, const char *desc);

void
SIM_register_class_attribute_with_user_data(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(conf_class_t *, lang_void *),
        lang_void *user_data_get,
        set_error_t (*set_attr)(conf_class_t *, attr_value_t *, lang_void *),
        lang_void *user_data_set,
        attr_attr_t attr, const char *type, const char *desc);

DESCRIPTION
Add the attribute name to the set of attributes of the class cls.

For SIM_register_attribute and SIM_register_class_attribute, the function get_attr is called with the object as argument, and returns the current value of the attribute. For SIM_register_attribute_with_user_data and SIM_register_class_attribute_with_user_data, the function get_attr takes an additional user data argument, which takes the value passed as user_data_get.

On error, get_attr should call SIM_attribute_error. The return value is then ignored; typically, SIM_make_attr_invalid is used to generate an explicitly invalid value.

If get_attr is a null pointer, the attribute will be write-only.

For SIM_register_attribute and SIM_register_class_attribute, the function set_attr is called with the object as argument. For SIM_register_attribute_with_user_data and SIM_register_class_attribute_with_user_data, the function set_attr takes an additional user data argument, which takes the value passed as user_data_set. The set_attr function is called when the attribute is initialised or changed. The argument value is owned by the caller, so any data from it must be copied.

The set_attr method should return Sim_Set_Ok if the new value could be set. On error, it should return an appropriate error code (usually Sim_Set_Illegal_Value), and optionally call SIM_attribute_error with an explanatory message.

If set_attr is a null pointer, the attribute will be read-only.

The attr parameter is one of Sim_Attr_Required, Sim_Attr_Optional or Sim_Attr_Pseudo.

Attributes marked Sim_Attr_Required or Sim_Attr_Optional are saved in checkpoints. Both set_attr and get_attr must be non-null for such attributes.

All attributes that are marked Sim_Attr_Required must be present in all configurations.

The set of permitted values is encoded in the string type.

The type strings are composed as follows:

SIM_register_class_attribute and SIM_register_class_attribute_with_user_data will register a class attribute. Class attributes are the same for all instances of the class.

EXECUTION CONTEXT
Global Context

SIM_register_class()

NAME
SIM_register_class — register class
SYNOPSIS
conf_class_t *
SIM_register_class(const char *NOTNULL name,
                   const class_data_t *NOTNULL class_data);

DESCRIPTION
This function is considered legacy. New code should use the SIM_create_class function to create new classes in the Simics simulator.

The function registers a new class that can be instantiated by calling the SIM_create_object function.

The name can contain upper and lower case ASCII letters, hyphens, underscores, and digits. It must not begin with a digit or a hyphen and must not end with a hyphen.

class_data may be freed when the function has returned.

typedef struct class_data {
        conf_object_t *(*alloc_object)(lang_void *data);
        lang_void *(*init_object)(conf_object_t *obj, lang_void *data);
        void (*finalize_instance)(conf_object_t *obj);

        void (*pre_delete_instance)(conf_object_t *obj);
        int (*delete_instance)(conf_object_t *obj);

        const char           *description;
        const char           *class_desc;
        class_kind_t          kind;
} class_data_t;

RETURN VALUE
Class structure, or NULL on error.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_create_class, SIM_register_class_alias, class_data_t

SIM_register_class_alias()

NAME
SIM_register_class_alias — register class alias
SYNOPSIS
void
SIM_register_class_alias(const char *NOTNULL alias, const char *NOTNULL name);

DESCRIPTION
Register an alias alias for the existing class class_name. Using aliases allows the read-configuration command to read configuration files that define objects of type alias, while the write-configuration command always uses class_name.

Aliases are used to support compatibility with old class names if a class is renamed. They can also be used to allow different modules, which define different specific implementations of the same generic base class, to read the same configuration files.

SEE ALSO
SIM_create_class, SIM_register_class
EXECUTION CONTEXT
Global Context

SIM_register_clock()

NAME
SIM_register_clock — register mandatory interface and attributes for clock objects
SYNOPSIS
int
SIM_register_clock(conf_class_t *NOTNULL cls,
                   const cycle_interface_t *NOTNULL iface);

DESCRIPTION
Register the cls class as a class for schedulable clock objects. This includes registering the cycle interface (iface), in addition to which SIM_register_clock registers the cell attribute required for scheduling the clock and some other Simics specific attributes. Simics will be able to schedule objects instantiated from the class cls.

The return value is 0 if everything works, and non-zero if something fails. Depending on the stage that failed, SIM_register_clock() will return the error value provided by SIM_register_interface().

RETURN VALUE
Returns non-zero on failure, 0 otherwise.
EXCEPTIONS
SimExc_General Thrown if the cycle interface has already been registered for this class.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_register_interface, SIM_register_attribute

SIM_register_compatible_interfaces()

NAME
SIM_register_compatible_interfaces — register earlier versions of interface
SYNOPSIS
void
SIM_register_compatible_interfaces(conf_class_t *NOTNULL cls,
                                   const char *NOTNULL name);

DESCRIPTION
Register any earlier versions of the interface name for class cls. The interface name must already be registered for the class.

When supported, this function lets a module implement a single version of an interface while still exporting earlier versions.

The following interfaces are currently accepted by this function, with the additional interfaces that are exported given in parenthesis: BREAKPOINT_QUERY_V2 (BREAKPOINT_QUERY), PROCESSOR_INFO_V2 (PROCESSOR_INFO).

EXCEPTIONS
SimExc_General Thrown if no interface is registered with the given name, if compatible versions of the interface have already been registered, or if the interface does not have any earlier versions that this function knows about.

EXECUTION CONTEXT
Global Context

SIM_register_interface()

NAME
SIM_register_interface, SIM_register_port_interface — register interface
SYNOPSIS
int
SIM_register_interface(conf_class_t *NOTNULL cls, const char *NOTNULL name,
                       const void *NOTNULL iface);

int
SIM_register_port_interface(conf_class_t *NOTNULL cls,
                            const char *NOTNULL name,
                            const void *NOTNULL iface,
                            const char *NOTNULL portname,
                            const char *desc);

DESCRIPTION
Register that cls implements the name interface. The interface itself should be supplied in the iface argument.

SIM_register_port_interface registers a port instance of an interface that must be looked up using SIM_get_port_interface. The portname parameter is the name of the port. The port name may not be the same as any attribute name used by the class. A short description of the port is provided with the desc parameter and should be identical for all interfaces for a port.

The data iface points to must not be deallocated or overwritten by the caller. Simics will use that data to store the interface structure. It will never be freed or written to by Simics.

RETURN VALUE
Returns non-zero on failure, 0 otherwise.
EXCEPTIONS
SimExc_General Thrown if the interface name is illegal, or if this interface has already been registered for this class.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_get_interface

SIM_register_port()

NAME
SIM_register_port — register port class
SYNOPSIS
void
SIM_register_port(conf_class_t *NOTNULL cls, const char *NOTNULL name,
                  conf_class_t *NOTNULL port_cls, const char *desc);

DESCRIPTION
Add a port named name of class port_cls to the set of ports defined by the class cls.

The result of this is that whenever an object of class cls is created, Simics will automatically create a port object of class port_cls. The name of the port object is created by appending . followed by the name string to the parent object's name.

If the port name contains dots or brackets, then intermediate port objects are registered as well. For instance, the port name x.array[2] will implicitly register ports x of class namespace, and x.array of class index-map.

Each port name may be registered at most once in a class. One exception is namespace classes: If the port is registered once as class namespace and once as some other class, then the namespace registration is dropped. Also, if a port is registered twice as class index-map, or twice as class namespace, then the second registration is dropped.

SEE ALSO
SIM_register_simple_port
EXECUTION CONTEXT
Global Context

SIM_register_simple_port()

NAME
SIM_register_simple_port — register port
SYNOPSIS
conf_class_t *
SIM_register_simple_port(conf_class_t *NOTNULL cls, const char *NOTNULL name,
                         const char *desc);

DESCRIPTION
Add a port named name to the set of ports defined by the class cls. The port will be an instance of a class named "parent_class_name.portname" where portname is the specified name of the port with leading namespaces omitted and any array indices removed. The port class is created if it does not exist already.
RETURN VALUE
The port class is returned.
SEE ALSO
SIM_register_port
EXECUTION CONTEXT
Global Context

SIM_register_typed_attribute()

NAME
SIM_register_typed_attribute, SIM_register_typed_class_attribute — register attribute
SYNOPSIS
int
SIM_register_typed_attribute(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(lang_void *user_data,
                                 conf_object_t *obj,
                                 attr_value_t *idx),
        lang_void *user_data_get,
        set_error_t (*set_attr)(lang_void *user_data,
                                conf_object_t *obj,
                                attr_value_t *val, attr_value_t *idx),
        lang_void *user_data_set,
        attr_attr_t attr, const char *type, const char *idx_type,
        const char *desc);

int
SIM_register_typed_class_attribute(
        conf_class_t *NOTNULL cls, const char *NOTNULL name,
        attr_value_t (*get_attr)(lang_void *ptr,
                                 conf_class_t *c,
                                 attr_value_t *idx),
        lang_void *user_data_get,
        set_error_t (*set_attr)(lang_void *ptr,
                                conf_class_t *c,
                                attr_value_t *val,
                                attr_value_t *idx),
        lang_void *user_data_set,
        attr_attr_t attr, const char *type, const char *idx_type,
        const char *desc);

DESCRIPTION
Add the attribute name to the set of attributes of the class cls.

The function get_attr is called with the object and the value from user_data_get as arguments, and returns the current value of the attribute.

On error, get_attr should call SIM_attribute_error. The return value is then ignored; typically, SIM_make_attr_invalid is used to generate an explicitly invalid value.

If get_attr is a null pointer, the attribute will be write-only.

The function set_attr is called with the object and the value from user_data_set as arguments when the attribute is initialised or changed. The argument value is owned by the caller, so any data from it must be copied.

The set_attr method should return Sim_Set_Ok if the new value could be set. On error, it should return an appropriate error code (usually Sim_Set_Illegal_Value), and optionally call SIM_attribute_error with an explanatory message.

If set_attr is a null pointer, the attribute will be read-only.

The attr parameter is one of Sim_Attr_Required, Sim_Attr_Optional, Sim_Attr_Session or Sim_Attr_Pseudo.

Attributes marked Sim_Attr_Required or Sim_Attr_Optional are saved in checkpoints. Both set_attr and get_attr must be non-null for such attributes.

All attributes that are marked Sim_Attr_Required must be present in all configurations.

The set of permitted values is encoded in the string type, and in idx_type for values during indexed access. A NULL value for either type string means that values of any type are permitted.

The type strings are composed as follows:

SIM_register_typed_class_attribute will register a class attribute. Class attributes are the same for all instances of the class.

RETURN VALUE
Returns zero if successful, and non-zero otherwise.
EXCEPTIONS
SimExc_General Thrown if the attribute name is invalid, and if the attribute is not a required, optional, session or pseudo attribute.

SimExc_AttrNotReadable Thrown if a checkpointed attribute is not readable.

SimExc_AttrNotWritable Thrown if a checkpointed attribute is not writable.

EXECUTION CONTEXT
Global Context

SIM_require_object()

NAME
SIM_require_object — make sure an object is fully configured
SYNOPSIS
void
SIM_require_object(conf_object_t *NOTNULL obj);

DESCRIPTION
If obj has not yet been set as configured, then that object's finalize method (post_init in DML) is run; otherwise, nothing happens. After completion of that method, obj will be set as configured.

Each object will have its finalize method called automatically, usually in hierarchical order, during object creation. Since it is only permitted to call methods on objects that have been configured, SIM_require_object is a way to allow such calls during finalisation by ensuring that those objects are correctly set up. A better way to call methods on other objects during finalization is to defer such calls to the objects_finalized method.

SIM_require_object may only be called from the finalize method of another object.

Finalisation cycles can occur if two or more objects call SIM_require_object on each other. Such cycles are treated as errors. To avoid them, call SIM_set_object_configured as soon as the object has reached a consistent state.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_object_is_configured, SIM_create_class, SIM_is_restoring_state

SIM_set_attribute_default()

NAME
SIM_set_attribute_default — set default value for an attribute in a child object
SYNOPSIS
set_error_t
SIM_set_attribute_default(conf_object_t *NOTNULL obj, const char *NOTNULL name,
                          attr_value_t val);

DESCRIPTION
SIM_set_attribute_default sets the default value for attribute name of object obj. The default value is used if no explicit value has been provided when the object is instantiated.

After the call val is still owned by the caller.

The function may only called while obj is being under construction and before its attributes have been set. More precisely, it is only legal to use this function from init_object callbacks or from an attribute setters belonging to a hierarchical ancestor of the object.

The main purpose of this function is setting suitable default attribute values for port objects.

RETURN VALUE
Returns Sim_Set_Ok if successful.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_register_port, SIM_register_class

SIM_set_class_data()

NAME
SIM_set_class_data — set class data
SYNOPSIS
void
SIM_set_class_data(conf_class_t *cls, lang_void *data);

DESCRIPTION
Set extra data for the specified class. This is particularly useful if the same class methods are used for multiple distinct classes, for instance for generated classes.

The class data can be fetched at any time during the object initialisation, using SIM_get_class_data.

SEE ALSO
SIM_get_class_data
EXECUTION CONTEXT
Global Context

Callbacks

SIM_cbdata_data()

NAME
SIM_cbdata_data — get cbdata data pointer
SYNOPSIS
FORCE_INLINE void *
SIM_cbdata_data(const cbdata_t *cbd);

DESCRIPTION
Return the data pointer of the callback data cbd.
SEE ALSO
cbdata_t

SIM_cbdata_type()

NAME
SIM_cbdata_type — get cbdata type pointer
SYNOPSIS
FORCE_INLINE const cbdata_type_t *
SIM_cbdata_type(const cbdata_t *cbd);

DESCRIPTION
Return a pointer to the type information of the callback data cbd.
SEE ALSO
cbdata_t

SIM_free_cbdata()

NAME
SIM_free_cbdata — free cbdata
SYNOPSIS
FORCE_INLINE void
SIM_free_cbdata(cbdata_t *cbd);

DESCRIPTION
Free the callback data cbd by calling its dealloc function.
SEE ALSO
cbdata_t

SIM_make_cbdata()

NAME
SIM_make_cbdata — create cbdata
SYNOPSIS
FORCE_INLINE cbdata_t
SIM_make_cbdata(const cbdata_type_t *type, void *data);

DESCRIPTION
Create new callback data of type type and value data.
SEE ALSO
cbdata_t

SIM_make_simple_cbdata()

NAME
SIM_make_simple_cbdata — create untyped cbdata
SYNOPSIS
FORCE_INLINE cbdata_t
SIM_make_simple_cbdata(void *obj);

DESCRIPTION
Create new untyped callback data of value data. An untyped callback data has no dealloc function.
SEE ALSO
cbdata_t

Errors and Exceptions

SIM_clear_exception()

NAME
SIM_clear_exception — clear pending exception
SYNOPSIS
sim_exception_t
SIM_clear_exception(void);

DESCRIPTION
Clears the currently pending frontend exception and returns the value of it.
RETURN VALUE
Returns the exception that was pending before the call, or SimExc_No_Exception.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_get_pending_exception, SIM_last_error

SIM_describe_pseudo_exception()

NAME
SIM_describe_pseudo_exception — return pseudo exception description
SYNOPSIS
const char *
SIM_describe_pseudo_exception(exception_type_t ex);

DESCRIPTION
This function returns a descriptive string for the specified exception_type_t.
RETURN VALUE
Exception description, or an error message if input is not a known pseudo-exception.
EXECUTION CONTEXT
Global Context
SEE ALSO
exception_type_t

SIM_get_pending_exception()

NAME
SIM_get_pending_exception — get current pending exception
SYNOPSIS
sim_exception_t
SIM_get_pending_exception(void);

DESCRIPTION
This function returns the exception type of the current pending exception, or SimExc_No_Exception if none available.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_clear_exception, SIM_last_error

SIM_last_error()

NAME
SIM_last_error — get error message from last frontend exception
SYNOPSIS
const char *
SIM_last_error(void);

DESCRIPTION
Returns the error message associated with the most recently raised frontend exception, even if that exception has been cleared.

The returned string is only valid until the next use of the Simics API in the same thread.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_clear_exception, SIM_get_pending_exception

Notifiers

SIM_add_notifier()

NAME
SIM_add_notifier — add a notifier callback
SYNOPSIS
notifier_handle_t *
SIM_add_notifier(
        conf_object_t *NOTNULL obj,
        notifier_type_t type,
        conf_object_t *subscriber,
        void (*callback)(conf_object_t *subscriber,
                         conf_object_t *NOTNULL notifier,
                         lang_void *data),
        lang_void *data);

DESCRIPTION
SIM_add_notifier installs a notifier of type type on the object obj.

The subscriber argument should be the object listening for the notification; this object is passed as the first argument to the callback function. The installed callback is automatically removed if the subscriber object is deleted. It is legal to pass NULL in the subscriber argument if there is no object associated with the callback.

The data argument is passed as the last argument to the callback function.

The function returns a handle to the installed notifier or NULL if the notifier type is not supported by the object.

Adding a notifier callback from another notifier callback of the same notifier type and object does not trigger an immediate callback invocation (from the same call to SIM_notify).

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_delete_notifier
SEE ALSO
SIM_delete_notifier, SIM_register_notifier

SIM_class_has_notifier()

NAME
SIM_class_has_notifier — query class for notifier
SYNOPSIS
bool
SIM_class_has_notifier(conf_class_t *NOTNULL cls, notifier_type_t type);

DESCRIPTION
Sim_class_has_notifier returns true if the class cls supports the notifier specified by type.
EXECUTION CONTEXT
Cell Context

SIM_delete_notifier()

NAME
SIM_delete_notifier — delete notifier callback
SYNOPSIS
void
SIM_delete_notifier(conf_object_t *NOTNULL obj, notifier_handle_t *handle);

DESCRIPTION
SIM_delete_notifier deletes the notifier callback specified by the handle handle.

Notifiers callbacks are deleted automatically when the subscribing object is deleted.

Deleting a notifier callback from another notifier callback of the same notifier type and object may or may not inhibit the last invocation of the deleted callback; this is undefined.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_add_notifier

SIM_describe_notifier()

NAME
SIM_describe_notifier, SIM_notifier_description — set short description
SYNOPSIS
void
SIM_describe_notifier(notifier_type_t type, const char *NOTNULL generic_desc);

const char *
SIM_notifier_description(notifier_type_t type);

DESCRIPTION
SIM_describe_notifier sets generic_desc as a generic description of the notification specified by the type argument. If the function is called multiple times then the description supplied during the last invocation of the function will be used. The generic description is shown when no description has been provided to the SIM_register_notifier or SIM_register_tracked_notifier functions.

SIM_notifier_description returns a generic description that was set with the SIM_describe_notifier for the notification specified by the type argument, or the empty string if no description has been set.

EXECUTION CONTEXT
Global Context

SIM_has_notifier()

NAME
SIM_has_notifier — query object for notifier
SYNOPSIS
bool
SIM_has_notifier(conf_object_t *NOTNULL obj, notifier_type_t type);

DESCRIPTION
SIM_has_notifier returns true if the object obj supports the notifier specified by type.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_notifier

SIM_notifier_type()

NAME
SIM_notifier_type — get notifier type
SYNOPSIS
notifier_type_t
SIM_notifier_type(const char *NOTNULL type);

DESCRIPTION
Given a notifier type type specified in the form of a string, return a notifier_type_t identifier which uniquely corresponds to this type.

This function always returns a valid notifier type; if a particular type string has not been seen before, then a new notifier type is created and associated with this string.

The string must consist of printable 7-bit ASCII characters, and by convention it should be expressed as a noun with words separated by dashes.

EXECUTION CONTEXT
Cell Context

SIM_notify()

NAME
SIM_notify — trigger notification callbacks
SYNOPSIS
void
SIM_notify(conf_object_t *NOTNULL obj, notifier_type_t type);

DESCRIPTION
The SIM_notify function triggers all callbacks associated with the notifier notifier which have been installed on the object obj.

The order in which notifier callbacks are invoked is undefined, but the same order every time.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_notifier, SIM_add_notifier

SIM_register_notifier()

NAME
SIM_register_notifier, SIM_register_tracked_notifier — register notifier
SYNOPSIS
void
SIM_register_notifier(conf_class_t *NOTNULL cls, notifier_type_t type,
                      const char *desc);

void
SIM_register_tracked_notifier(conf_class_t *NOTNULL cls, notifier_type_t type,
                              const char *desc,
                              void (*subscribed_changed)(conf_object_t *obj,
                                                         notifier_type_t type,
                                                         bool has_subscribers));

DESCRIPTION
These functions add the notifier type (returned by the SIM_notifier_type function) to the set of notifiers supported by the class cls. The desc argument can be used to provide any relevant documentation, e.g., information about when the notifier is triggered and how it should be used by the objects that subscribe to it. For uniformity, we suggest formatting the description similar to this one of the "frequency-change" notifier: "Notifier that is triggered when frequency changes. New frequency can be read via the frequency interface of the object."

SIM_register_notifier is the base registration function. SIM_register_tracked_notifier accepts an additional argument subscribed_changed. If not NULL, this callback will be invoked whenever a notifier of the type type is installed (see SIM_add_notifier) or deleted (see SIM_delete_notifier) on an object of class cls. The obj argument passed to subscribed_changed is the object of the class cls.

It is legal to call SIM_register_notifier multiple times for the same class and the same notifier type. All subsequent invocations done after the notifier was registered are ignored. Calling SIM_register_tracked_notifier multiple times registers multiple subscribed_changed callbacks. All of them will be invoked as it is specified above.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_notifier_type, SIM_notify, SIM_add_notifier

Global Notifiers

SIM_add_global_notifier()

NAME
SIM_add_global_notifier — add a global notifier callback
SYNOPSIS
global_notifier_callback_t *
SIM_add_global_notifier(
        global_notifier_type_t type,
        conf_object_t *subscriber,
        void (*callback)(conf_object_t *subscriber, lang_void *data),
        lang_void *data);

DESCRIPTION
SIM_add_global_notifier installs a callback on the global notifier of type type. The callback will be executed in Global Context. The callback can uninstall itself, using SIM_delete_global_notifier, but must not uninstall any other global notifiers.

The subscriber argument should be the object listening on the notifier; this object is passed as the first argument to the callback. The installed callback is automatically removed if the subscriber object is deleted. It is legal to pass NULL in the subscriber argument if there is no object associated with the callback.

The function returns a handle to the installed callback or NULL if the notifier type is unknown.

Adding a notifier callback from another notifier callback of the same notifier type does not trigger an immediate callback invocation.

EXECUTION CONTEXT
Global Context

SIM_add_global_notifier_once()

NAME
SIM_add_global_notifier_once — add a global notifier callback
SYNOPSIS
global_notifier_callback_t *
SIM_add_global_notifier_once(
        global_notifier_type_t type,
        conf_object_t *subscriber,
        void (*callback)(conf_object_t *subscriber, lang_void *data),
        lang_void *data);

DESCRIPTION
The SIM_add_global_notifier_once is similar to SIM_add_global_notifier, except that the notifier will be removed automatically after the callback has been called once.
EXECUTION CONTEXT
Global Context

SIM_delete_global_notifier()

NAME
SIM_delete_global_notifier — delete global notifier callback
SYNOPSIS
void
SIM_delete_global_notifier(global_notifier_callback_t *handle);

DESCRIPTION
SIM_delete_global_notifier deletes the global notifier callback specified by the handle handle.

Global notifier callbacks are deleted automatically when the subscribing object is deleted.

Deleting a notifier callback from another notifier callback of the same notifier type may or may not inhibit the last invocation of the deleted callback; this is undefined.

EXECUTION CONTEXT
Global Context

Haps

SIM_hap_add_type()

NAME
SIM_hap_add_type — register a new hap type
SYNOPSIS
hap_type_t
SIM_hap_add_type(const char *NOTNULL hap,
                 const char *NOTNULL params,
                 const char *param_desc,
                 const char *index,
                 const char *desc,
                 int unused);

DESCRIPTION
Creates a run-time defined hap type.

The params parameter specifies the argument that callbacks for this hap is called with; e.g., "s" or "II". The first two arguments are always lang_void * and conf_object_t * respectively, and should not be included in that string. The table below shows which characters may be used, and what their meaning is:

ian int
Ian int64 (64 bit integer)
ean exception_type_t
oa script specific object; i.e., void * in C and any Python object in Python
sa string
ma memory transaction (generic_transaction_t * in C)
ca configuration object (conf_object_t * in C)

param_desc should be a string of space-separated parameter names, or NULL if params is the empty string. There should be one word in param_desc for each character in params.

index is a string describing the index value for this hap, or NULL if there is no index value.

desc is a description string for the hap.

EXCEPTIONS
SimExc_General Thrown if hap is already defined. However, consequent calls with the same parameters will be successful, and return the same hap type number each time.
RETURN VALUE
The hap type number or -1 on error.

EXECUTION CONTEXT
Global Context

SIM_hap_get_name()

NAME
SIM_hap_get_name — get hap name by number
SYNOPSIS
const char *
SIM_hap_get_name(hap_type_t hap);

DESCRIPTION
Returns the name of hap, or NULL for no such hap. The returned value is a static string that should not be modified or freed by the caller.
EXECUTION CONTEXT
Cell Context

SIM_hap_get_number()

NAME
SIM_hap_get_number — get hap number by name
SYNOPSIS
hap_type_t
SIM_hap_get_number(const char *NOTNULL hap);

DESCRIPTION
Return the runtime number associated with a hap identifier. All haps are listed in the Haps chapter in each reference manual.
EXCEPTIONS
SimExc_Lookup Thrown if no hap is associated with name hap.

RETURN VALUE
The hap type number, or 0 on failure.
EXECUTION CONTEXT
Global Context

SIM_hap_is_active()

NAME
SIM_hap_is_active, SIM_hap_is_active_obj, SIM_hap_is_active_obj_idx — check if hap has callbacks
SYNOPSIS
bool
SIM_hap_is_active(hap_type_t hap);

bool
SIM_hap_is_active_obj(hap_type_t hap, conf_object_t *NOTNULL obj);

bool
SIM_hap_is_active_obj_idx(hap_type_t hap, conf_object_t *NOTNULL obj,
                          int64 index);

DESCRIPTION
Indicate whether the hap has any callback functions to be called when the hap is triggered with the given arguments (object and index). The return value is approximate: if false, no functions would be called; if true, there may be functions to call.

The SIM_hap_is_active function should be avoided; it may be slower and less precise than the other variants.

EXECUTION CONTEXT
Cell Context

SIM_hap_occurred_always()

NAME
SIM_hap_occurred_always, SIM_c_hap_occurred_always_vararg, SIM_c_hap_occurred_always, SIM_hap_occurred, SIM_c_hap_occurred_vararg, SIM_c_hap_occurred — trigger a hap occurrence
SYNOPSIS
int
SIM_hap_occurred_always(hap_type_t hap, conf_object_t *obj,
                        int64 value, attr_value_t *NOTNULL list);

int
SIM_c_hap_occurred_always_vararg(hap_type_t hap, conf_object_t *obj,
                                 int64 value, va_list ap);

int
SIM_c_hap_occurred_always(hap_type_t hap, conf_object_t *obj,
                          int64 value, ...);

int
SIM_hap_occurred(hap_type_t hap, conf_object_t *obj,
                 int64 value, attr_value_t *NOTNULL list);

int
SIM_c_hap_occurred_vararg(hap_type_t hap, conf_object_t *obj,
                          int64 value, va_list ap);

int
SIM_c_hap_occurred(hap_type_t hap, conf_object_t *obj,
                   int64 value, ...);

DESCRIPTION
These functions are used to trigger a hap of type hap. When a hap triggers, all callback functions installed on the hap are called.

The obj argument is the object that the hap triggering is associated with. It may be NULL for haps that are not associated with an object.

The value argument is used for filtering out callback functions to call based on the index or range that they are installed for. What the index or range corresponds to is hap specific, but could for example be the exception number for the Core_Exception hap.

SIM_hap_occurred() will only call the callbacks once every simulated cycle; if this hap is triggered several times during one cycle, the callbacks will still only be called once. The SIM_hap_occurred_always() function will always call the hap callback functions every time. It is recommended that SIM_hap_occurred_always() is used.

These hap triggering functions return whether or not there were any matching callback function registered on the hap. This can be useful information when one wants a default behavior to be triggered (for example, stopping the simulation) if nobody is listening to the hap.

The hap-specific parameters to the callback function can be passed in various ways: The SIM_c_hap_occurred... functions are only available in C/C++ and are variadic or take a va_list as argument. SIM_hap_occurred and SIM_hap_occurred_always are mainly intended to be used from Python, taking the parameters from an attribute value of list type, or an empty list ([]) if no parameters are passed. In all cases, the number and types of passed parameters must agree with the hap type definition.

RETURN VALUE
The return value is 0 if no callbacks are registered on the hap and non-zero if there are callbacks registered.
EXCEPTIONS
SimExc_General Thrown if hap is not a valid hap type or if the values in the list argument are of the wrong type.

EXECUTION CONTEXT
Cell Context

SIM_hap_remove_type()

NAME
SIM_hap_remove_type — remove a hap type
SYNOPSIS
void
SIM_hap_remove_type(const char *NOTNULL hap);

DESCRIPTION
Remove a run-time defined hap type.
EXECUTION CONTEXT
Global Context

Logging

SIM_log_info()

NAME
SIM_log_info, SIM_log_spec_violation, SIM_log_unimplemented, SIM_log_error, SIM_log_critical, SIM_log_message — output log message
SYNOPSIS
void
SIM_log_info(int level, conf_object_t *NOTNULL dev, int grp,
             const char *NOTNULL fmt, ...);

void
SIM_log_spec_violation(int level, conf_object_t *NOTNULL dev, int grp,
                       const char *NOTNULL fmt, ...);

void
SIM_log_unimplemented(int level, conf_object_t *NOTNULL dev, int grp,
                      const char *NOTNULL fmt, ...);

void
SIM_log_error(conf_object_t *NOTNULL dev, int grp,
              const char *NOTNULL fmt, ...);

void
SIM_log_critical(conf_object_t *NOTNULL dev, int grp,
                 const char *NOTNULL fmt, ...);

void
SIM_log_message(conf_object_t *obj, int level, uint64 group_ids,
                log_type_t log_type, const char *message);

DESCRIPTION
These logging functions are used to emit information and error messages.

The level parameter indicates the importance; a lower value means a more important message. SIM_log_error has no level parameter and will always emit messages.

level should be between 1 and 4:

  1. important messages that are always printed
  2. "high-level" informative messages
  3. standard debug messages
  4. detailed information, such as register accesses

The grp parameter should have a bit set for each log group that the message corresponds to, as defined by the SIM_log_register_groups function, while a value of 0 equals any group.

The level and grp parameters allow the user to selectively display more or fewer messages using the log-level, log-group and log-type commands.

The fmt argument and those following it are used for string formatting in the same way as in the standard sprintf function.

The logging functions are among the few Simics API functions that may be called while a frontend exception is pending.

Note that the macro versions of these functions, listed below, are usually more efficient.

The use of the different functions is discussed in Simics Model Builder User's Guide, section "Logging":

If the sim->stop_on_error attribute is set to true, for example if Simics was started with the --stop-on-error command line flag, then Simics will exit with an error code when a log message of the error type is generated.

#define SIM_LOG_INFO(level, dev, grp, ...)
#define SIM_LOG_SPEC_VIOLATION(level, dev, grp, ...)
#define SIM_LOG_UNIMPLEMENTED(level, dev, grp, ...)
#define SIM_LOG_ERROR(dev, grp, ...)
#define SIM_LOG_CRITICAL(dev, grp, ...)
#define SIM_LOG_INFO_ONCE(level1, level2, dev, grp, ...)
#define SIM_LOG_SPEC_VIOLATION_ONCE(level1, level2, dev, grp, ...)
#define SIM_LOG_UNIMPLEMENTED_ONCE(level1, level2, dev, grp, ...)
   

EXECUTION CONTEXT
All contexts (including Threaded Context)
SEE ALSO
SIM_log_register_groups, SIM_attribute_error

SIM_log_level()

NAME
SIM_log_level, SIM_set_log_level — set and get log level
SYNOPSIS
unsigned
SIM_log_level(const conf_object_t *NOTNULL obj);

void
SIM_set_log_level(conf_object_t *NOTNULL obj, unsigned level);

DESCRIPTION
Retrieve or set the log level of an object. The level must be in the range 0..4 inclusive. Higher values mean more detailed logging.
EXECUTION CONTEXT
Cell Context

SIM_log_register_groups()

NAME
SIM_log_register_groups — register names of log groups
SYNOPSIS
void
SIM_log_register_groups(conf_class_t *NOTNULL cls,
                        const char *const *NOTNULL names);

DESCRIPTION
Register a list of log groups that an object can use to separate messages. The order of the groups in the list defines the group ids that should be used in calls to SIM_log_info and similar functions. The group_ids argument to those functions should have a bit set corresponding to the group; i.e., a value of 1 for the first group, 2 for the second, 4 for the third, etc. names should be a NULL-terminated array.

A class may have up to 63 user-defined log groups.

The Default_Log_Group group is present on all classes. It is used for log entries where no group is specified.

EXCEPTIONS
SimExc_General Thrown in case of an error, e.g. if log groups are already registered.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_log_info

Transaction Types

atom_id_t

NAME
atom_id_t
DESCRIPTION
Each atom type is associated with a unique id, the atom_id_t. Most atoms types are pre-defined by Simics Core and have static ids, but there are also dynamically assigned ids which are used for custom atom types.

Atom ids are internal to Simics Core and should never be used explicitly by a Simics models. Instead, there are API functions like e.g. ATOM_size or ATOM_initiator which should be used instead.

atom_t

NAME
atom_t
DESCRIPTION
The atom_t type is a container type for tagged data associated with a transaction. The kind of data stored in the atom is determined by the id field, and a pointer to the data or the data itself is stored in the ptr field.

Atoms should always be initialized using provided constructor functions like ATOM_flags or ATOM_size. Usage of the constructors ensures that the data payload is of the correct type and that the id is set to the correct value.

Atom lists must be terminated with the special ATOM_LIST_END marker.

transaction_completion_t

NAME
transaction_completion_t
SYNOPSIS
typedef exception_type_t (*transaction_completion_t)(
        conf_object_t *obj, transaction_t *t, exception_type_t ex);

DESCRIPTION
Callback invoked when an asynchronous transaction is completed. The callback is stored in a completion atom belonging to the transaction t. Similarly, obj is an object stored in either an owner atom or an initiator atom. The former takes precedence if both are present.

Completion callbacks are only invoked for transactions monitored with either SIM_monitor_transaction or SIM_monitor_chained_transaction, or for transactions deferred with SIM_defer_owned_transaction.

The completion status for the operation is given in the ex argument, and is usually equal to Sim_PE_No_Exception.

The return value of the callback is the completion status for the transaction t. This status is used to complete the parent transaction if the transaction is being monitored with SIM_monitor_chained_transaction. The return value is also returned by SIM_monitor_transaction or SIM_monitor_chained_transaction when a transaction is completed synchronously.

If the callback returns Sim_PE_Deferred, then the transaction t is left uncompleted. It must then be completed later on by an explicit call to SIM_complete_transaction.

transaction_flags_t

NAME
transaction_flags_t
SYNOPSIS
typedef enum {
        Sim_Transaction_Fetch         = 1 << 0,
        Sim_Transaction_Write         = 1 << 1,
        Sim_Transaction_Control       = 1 << 2,

        Sim_Transaction_Inquiry       = 1 << 8,
        Sim_Transaction_Incoherent    = 1 << 9,
        Sim_Transaction_Atomic        = 1 << 10,
} transaction_flags_t;

DESCRIPTION
The transaction_flags_t type is bitmask used to specify the transaction type. It is a combination of the following bits:

Sim_Transaction_Fetch indicates that the transaction is an instruction fetch.

Sim_Transaction_Write is set if the transaction is a write.

Sim_Transaction_Control is set if the transaction does not actually transfer any data. One example of such transactions is cache control operations.

The Sim_Transaction_Inquiry bit signifies that side effects normally triggered by the transaction should be suppressed. Examples of side effects include triggering breakpoints and clearing "read-to-clear" device registers.

When neither Sim_Transaction_Fetch nor Sim_Transaction_Write is set the transaction is a read transaction.

transaction_t

NAME
transaction_t
DESCRIPTION
A transaction_t represents a memory transaction. The properties of the transaction is stored in the form of an atom list, where each atom describes a particular aspect of the transaction, like the size of the transaction.

The field atoms points to the atoms list, which must be terminated with the constant ATOM_LIST_END.

The prev field points to an optional parent transaction. If a particular atom is not found in the atoms list, then the parent's list of atoms is consulted instead. The prev pointer is also used when a chained transaction is monitored with SIM_monitor_chained_transaction.

Besides the fields above, the transaction contains some internal fields that should be initialized to 0. The internal fields should not be referenced explicitly since they are likely to change in future Simics releases.

For details, please refer to "Transactions" chapter in the Model Builder's User Guide.

Transactions

ATOM_flags()

NAME
ATOM_flags, ATOM_data, ATOM_size, ATOM_initiator, ATOM_completion, ATOM_list_end — transaction atom's constructor
SYNOPSIS
static inline atom_t ATOM_flags(transaction_flags_t val);

static inline atom_t ATOM_data(uint8 *val);

static inline atom_t ATOM_size(uint32 val);

static inline atom_t ATOM_initiator(conf_object_t *val);

static inline atom_t ATOM_completion(transaction_completion_t val);

static inline atom_t ATOM_list_end(int val);

DESCRIPTION
The functions construct transaction atoms.

ATOM_flags returns a transaction atom specifying transaction flags (see description of transaction_flags_t for information about available transaction flags).

ATOM_data returns a transaction atom that holds the pointer to a buffer that is used to get the data from (for write transactions) to store the data to (for read and instruction fetch transactions).

ATOM_size returns a transaction atom that holds the size of a transaction.

ATOM_initiator returns a transaction atom that holds the initiator of a transaction.

ATOM_completion creates a completion atom - a special atom that holds a callback that is invoked when a transaction is completed asynchronously.

ATOM_list_end returns a special atom that should end the list of transaction atoms. One can use the ATOM_LIST_END macro instead.

RETURN VALUE
An atom value
EXECUTION CONTEXT
All contexts (including Threaded Context)
EXAMPLE
Sample C code to create a 1-byte read transaction:
     uint8 val;
     atom_t atoms[] = {
         // the flags atom value specifies the transaction type:
         // - 0 defines a read transaction
         // - Sim_Transaction_Write - a write transaction
         // - Sim_Transaction_Fetch - an instruction fetch transaction
         ATOM_flags(0),

         ATOM_data(&val),
         ATOM_size(sizeof val),
         ATOM_initiator(obj),
         ATOM_LIST_END
     };
     transaction_t t = { atoms };
   

SEE ALSO
transaction_t, transaction_flags_t, transaction_completion_t

SIM_complete_transaction()

NAME
SIM_complete_transaction — complete a deferred transaction
SYNOPSIS
void
SIM_complete_transaction(transaction_t *t, exception_type_t status);

DESCRIPTION
The SIM_complete_transaction completes a previously deferred transaction t using the exception status status. The transaction t must be the return value of a previous call to SIM_defer_transaction or a transaction passed to SIM_defer_owned_transaction.

If the transaction t has not been monitored, then the completion code is stored in an internal transaction field until the transaction is monitored with SIM_monitor_transaction or SIM_monitor_chained_transaction, at which time the completion callback is invoked using the stored completion code.

Note that SIM_complete_transaction is normally only used to complete asynchronous transactions. Synchronous transactions are completed by returning the appropriate return code directly from the issue method.

SEE ALSO
SIM_defer_transaction, SIM_monitor_transaction, SIM_monitor_chained_transaction, SIM_poll_transaction
EXECUTION CONTEXT
Cell Context

SIM_defer_owned_transaction()

NAME
SIM_defer_owned_transaction — defer transaction completion using an existing transaction
SYNOPSIS
transaction_t *
SIM_defer_owned_transaction(transaction_t *t);

DESCRIPTION
When a transaction cannot be completed immediately in the issue method of the transaction interface, then the completion can be deferred to a later time by calling SIM_defer_transaction which allocates a new transaction. One alternative is calling SIM_defer_owned_transaction which allows the caller to allocate the deferred transaction explicitly, in which case provides a heap-allocated transaction t which is linked to the transaction which should be deferred through its prev field. The provided transaction should have an owner and a completion atoms, which are used when the deferred transaction is completed.

When a transaction is deferred, the status code Sim_PE_Deferred must be returned rom the issue method of the transaction interface.

RETURN VALUE
The transaction t, or NULL if the transaction was issued synchronously and cannot be deferred. When a transaction cannot be deferred, the issue method may choose to return the error status Sim_PE_Async_Required.
EXECUTION CONTEXT
Cell Context

SIM_defer_transaction()

NAME
SIM_defer_transaction — defer transaction completion
SYNOPSIS
transaction_t *
SIM_defer_transaction(conf_object_t *obj, transaction_t *t);

DESCRIPTION
When a transaction cannot be completed immediately in the issue method of the transaction interface, then the completion can be deferred to a later time by calling SIM_defer_transaction with the transaction as a parameter.

The SIM_defer_transaction function returns a new transaction pointer which is guaranteed to be available until it is completed with a call to SIM_complete_transaction. When a transaction is deferred, the status code Sim_PE_Deferred must be returned from the issue method of the transaction interface.

RETURN VALUE
Deferred transaction, or NULL if the transaction was issued synchronously and cannot be deferred. When a transaction cannot be deferred, the issue method may choose to return the error status Sim_PE_Async_Required.
EXECUTION CONTEXT
Cell Context

SIM_get_transaction_bytes()

NAME
SIM_get_transaction_bytes, SIM_get_transaction_bytes_offs, SIM_get_transaction_value_le, SIM_get_transaction_value_be — get transaction data payload
SYNOPSIS
void
SIM_get_transaction_bytes(const transaction_t *t, buffer_t buf);

void
SIM_get_transaction_bytes_offs(const transaction_t *t, unsigned offs,
                               buffer_t buf, bool zerofill_holes);

uint64
SIM_get_transaction_value_le(const transaction_t *t);

uint64
SIM_get_transaction_value_be(const transaction_t *t);

DESCRIPTION
Copy the data payload from a transaction to the provided buffer buf. The size of the buffer must match the size of the transaction.

SIM_get_transaction_bytes_offs retrieves the bytes of the transaction which starts at offset offs. The sum of the offset and the buffer size must not exceed the transaction size.

SIM_get_transaction_value_le returns the value obtained when the transaction buffer is interpreted as an encoded little endian integer. The size of the transaction must not exceed 8 for this function to be used.

SIM_get_transaction_value_be returns the value obtained when the transaction buffer is interpreted as an encoded big endian integer.

EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_get_transaction_id()

NAME
SIM_get_transaction_id — obtain checkpoint ID for a deferred a transaction
SYNOPSIS
int64
SIM_get_transaction_id(transaction_t *t);

DESCRIPTION
The SIM_get_transaction_id function is used by objects that checkpoint the transaction state. The returned ID uniquely identifies the transaction and should be stored in a checkpoint together with the relevant state that the object keeps for the transaction. The same ID should then be given to SIM_reconnect_transaction during checkpoint load.

This function must only be called on a deferred transaction.

SEE ALSO
SIM_reconnect_transaction
EXECUTION CONTEXT
Global Context

SIM_inspect_address_routing()

NAME
SIM_inspect_address_routing — track the route of a transaction through memory hierarchy
SYNOPSIS
bool
SIM_inspect_address_routing(const map_target_t *NOTNULL mt,
                            transaction_t *NOTNULL t,
                            uint64 addr,
                            bool (*NOTNULL callback)(
                                    const map_target_t *mt,
                                    const transaction_t *t,
                                    uint64 addr,
                                    uint64 base,
                                    uint64 start,
                                    uint64 size,
                                    access_t access,
                                    translation_flags_t flags,
                                    lang_void *data),
                            lang_void *data);

DESCRIPTION
This function allows to track the route of a transaction through memory hierarchy. The route is traced as if the transaction t was issued at the address addr to the destination represented by the map target mt. Note that when this function is used the endpoint of the transaction will not be accessed.

The transaction t can be of any type: a read, a write, or an instruction fetch. Please note that the type of the transaction may affect its path through memory hierarchy. The size of the transaction t is ignored: when accesses are done larger transactions may be split depending on how the memory mapping are set up; no such splitting is occurred while the transaction route is traced with SIM_inspect_address_routing. It is allowed to use transactions with zero size.

The callback callback will be called for every device (memory spaces and translator objects) encountered on the transaction’s route to the destination as well as for the destination device (this is usually a device implementing the transaction interface or the io_memory interface). The first invocation of callback is done with the mt argument itself.

The arguments passed to the callback are:

- mt is a map target representing an intermediate device or the endpoint. If nothing is mapped then NULL (or None in Python) value is passed. The map target value should not be cached but it can be inspected

- t is usually the original transaction, but it can be also a new transaction in the case when additional atoms were appended to the original transaction via the transaction chaining (see, e.g., the documentation for the transaction_translator interface)

- addr is address inside the intermediate device or the endpoint where the transaction is sent

- base, start, size, access, and flags arguments describe the mapping which led to the mt map target. These arguments (except for access) are the same as the fields of the translation_t structure. Please refer to the translation_t's documentation for their description. The access argument is a bitmask specifying access types. The bit corresponding to the type of the t transaction is always set. Other access bits may also be set optionally. But the latter is not guaranteed even if read/write/execute accesses are routed similarly

- data is the data argument passed to SIM_inspect_address_routing

The callback callback may return false to stop inspection. I.e. if the false value is returned callback will not be invoked any more.

RETURN VALUE
The function returns false if callback returned false in order to stop the inspection. Otherwise, true is returned.
EXAMPLE
 
# The following example shows how one can determine
# the destination of a read transaction sent from a CPU object:

import conf, simics

def get_destination(memory_space, address):
    '''Example function returning destination object for the access
    sent to address in the memory space memory_space.'''
    mt = simics.SIM_new_map_target(memory_space, None, None)
    t = simics.transaction_t()  # read transaction of zero size
    l = [None]  # data for the callback

    def callback(mt, t, addr, base, start, size, access, flags, l):
        l[0] = (simics.SIM_map_target_object(mt)
                if mt is not None
                else None)
        return True

    simics.SIM_inspect_address_routing(mt, t, address, callback, l)

    # We free mt here but it can be saved and reused if needed.
    # Transaction t can also be reused.
    simics.SIM_free_map_target(mt)
    return l[0]

# Please specify here CPU object and address you are interested in:
cpu = simics.SIM_get_processor(0)
address_of_access = 0x1000

dest = get_destination(
    cpu.iface.processor_info_v2.get_physical_memory(),
    address_of_access)

print("Destination: ",
      dest.name if dest is not None else "'nothing is mapped'")

EXECUTION CONTEXT
Cell Context

SIM_inspect_breakpoints()

NAME
SIM_inspect_breakpoints — find out breakpoints that a transaction would trigger
SYNOPSIS
bool
SIM_inspect_breakpoints(
        const map_target_t *NOTNULL mt,
        transaction_t *NOTNULL t,
        uint64 start,
        uint64 end,
        bool (*NOTNULL callback)(
                conf_object_t *trigger_object,
                breakpoint_set_t bp_set,
                const transaction_t *t,
                uint64 start,
                uint64 end,
                lang_void *data),
        lang_void *data);

DESCRIPTION
The function allows to find out the breakpoints that would be triggered if a transaction t would be sent to the address range inside the map target mt. The address range is specified by the start and end arguments and includes both start and end of the range. Only breakpoints matching the transaction t's type (i.e., a read, a write, or an instruction fetch) are reported. The size of the transaction t is ignored and can be zero.

For all matching breakpoints Simics invokes callback. The callback function may be called multiple times: with different trigger_object objects. The callback function gets the following two arguments that describe the breakpoints:

- trigger_object is the object implementing the breakpoint_trigger interface. The interface is used during simulation to signal that an access triggers a breakpoint

- bp_set is a set of breakpoints. The breakpoints match the transaction t's type and intersect the [start, end] range within the mt map target. Bp_set should only be used inside callback. Data ownership is preserved by the caller (i.e., Simics)

Auxiliary information is provided to callback via the following arguments:

- t is usually the original transaction, but it can be also a new transaction in the case when additional atoms were appended to the original transaction via the transaction chaining (see, e.g., the documentation for the transaction_translator interface)

- callback's start and end arguments specify an address range inside the trigger_object Simics object where the accesses to the requested address range inside the mt map target would go. The size of the range reported to callback may be smaller than the size of the requested range. This may occur, e.g., when different parts of the original address range are translated to different destinations based the memory mappings of the simulated machine

- callback's data is the data argument passed to SIM_inspect_breakpoints

The callback function may return false to stop searching for breakpoints. I.e. if the false value is returned callback will not be invoked any more even if more breakpoints are present.

The SIM_inspect_breakpoints function is an inspection function: the endpoint of the transaction is never accessed when the function is used.

RETURN VALUE
The function returns false if callback returned false in order to stop the inspection. Otherwise, true is returned.
EXECUTION CONTEXT
Cell Context

SIM_issue_transaction()

NAME
SIM_issue_transaction — issue transaction
SYNOPSIS
exception_type_t
SIM_issue_transaction(const map_target_t *NOTNULL mt,
                      transaction_t *NOTNULL t, uint64 addr);

DESCRIPTION
SIM_issue_transaction issues the transaction t with the address addr to the destination represented by the map target mt. In Python, the mt argument can also be a conf_object_t.
RETURN VALUE
The function returns Sim_PE_Deferred if the transaction was deferred for completion at a some later time. The corresponding pseudo exception is returned if the transaction completed directly (normally Sim_PE_No_Exception or Sim_PE_IO_Not_Taken).
SEE ALSO
SIM_new_map_target, SIM_free_map_target, SIM_defer_transaction, SIM_complete_transaction, SIM_monitor_transaction, SIM_transaction_wait
EXECUTION CONTEXT
Cell Context

SIM_monitor_transaction()

NAME
SIM_monitor_transaction, SIM_monitor_chained_transaction — monitor a transaction for deferred completion
SYNOPSIS
exception_type_t
SIM_monitor_transaction(transaction_t *t, exception_type_t ex);

exception_type_t
SIM_monitor_chained_transaction(transaction_t *t, exception_type_t ex);

DESCRIPTION
The SIM_monitor_transaction function monitors an asynchronously issued transaction for completion. A transaction is asynchronously issued if it has a completion atom with a callback which is not NULL. The function should be called after the transaction has been issued, and the ex status code should be the return value from function used to issue the transaction, for example the issue method of the transaction interface.

If ex equals Sim_PE_Deferred, then SIM_monitor_transaction will check if the transaction has in fact been completed already, and in that case, immediately invoke the completion callback. If the transaction is still uncompleted, then it will be marked as monitored and a subsequent call to SIM_complete_transaction will immediately complete the transaction by invoking the completion callback.

If ex is not equal to Sim_PE_Deferred, then the transaction has been completed synchronously, and the completion callback is called using ex as the completion status.

Note that it is illegal to call SIM_monitor_transaction for transactions that do not have a valid completion callback.

SIM_monitor_chained_transaction is similar to SIM_monitor_transaction except that when a deferred transaction is completed, its parent transaction will be completed too.

RETURN VALUE
Exception code returned by the completion function, or Sim_PE_Deferred if the transaction is monitored for completion at a later time.
SEE ALSO
SIM_defer_transaction, SIM_complete_transaction
EXECUTION CONTEXT
Cell Context

SIM_poll_transaction()

NAME
SIM_poll_transaction — check if a transaction has completed
SYNOPSIS
exception_type_t
SIM_poll_transaction(transaction_t *t);

DESCRIPTION
The SIM_poll_transaction function checks if the transaction t is marked as completed, in which case the associated status code is returned and the completion status for the transaction is cleared. If the transaction is uncompleted, then Sim_PE_Deferred is returned.

It is illegal to call SIM_poll_transaction on a transaction which is monitored for completion using e.g. the SIM_monitor_transaction function.

SEE ALSO
SIM_complete_transaction
EXECUTION CONTEXT
Cell Context

SIM_reconnect_transaction()

NAME
SIM_reconnect_transaction — register that a deferred transaction has been restored
SYNOPSIS
void
SIM_reconnect_transaction(transaction_t *t, int64 id);

DESCRIPTION
The SIM_reconnect_transaction function is used by objects that checkpoint the transaction state. It should be called when the relevant state has been read from a checkpoint.
SEE ALSO
SIM_get_transaction_id
EXECUTION CONTEXT
Global Context

SIM_register_python_atom_type()

NAME
SIM_register_python_atom_type — register an atom type which takes plain Python objects
SYNOPSIS
void
SIM_register_python_atom_type(const char *NOTNULL name);

DESCRIPTION
Register an atom type named name. The atom type can be used from Python and can hold any Python object.
EXECUTION CONTEXT
Global Context

SIM_replace_transaction()

NAME
SIM_replace_transaction — replace transaction
SYNOPSIS
void
SIM_replace_transaction(transaction_t *t_old, transaction_t *t_new);

DESCRIPTION
Replace a transaction t_old with a new transaction t_new.

A transaction which has been issued and is deferred by some downstream device can be replaced with a different transaction by initiator. This is mostly useful when a transaction is allocated on the stack and it turns out that the transaction is not completed synchronously, in which case SIM_replace_transaction can be used to move the transaction to e.g. the heap.

This function ensures that the deferred transaction is properly linked with the t_new transaction. It is the caller's responsibility to fill in the contents of the new transaction, including the prev pointer.

It is illegal to replace a transaction which has been monitored.

EXECUTION CONTEXT
Cell Context

SIM_set_transaction_bytes()

NAME
SIM_set_transaction_bytes, SIM_set_transaction_bytes_offs, SIM_set_transaction_value_le, SIM_set_transaction_value_be, SIM_set_transaction_bytes_constant — set transaction data payload
SYNOPSIS
void
SIM_set_transaction_bytes(const transaction_t *t, bytes_t bytes);

void
SIM_set_transaction_bytes_offs(const transaction_t *t, unsigned offs,
                               bytes_t bytes);

void
SIM_set_transaction_value_le(const transaction_t *t, uint64 value);

void
SIM_set_transaction_value_be(const transaction_t *t, uint64 value);

void
SIM_set_transaction_bytes_constant(const transaction_t *t, uint8 value);

DESCRIPTION
Set the data payload of a transaction to the contents provided by bytes. The number of provided bytes must match the transaction size exactly.

The SIM_set_transaction_bytes_offs function sets some bytes of the transaction starting at offset offs. The sum of the offset and the number of provided bytes must not exceed the transaction size.

The SIM_set_transaction_value_le function sets the transaction bytes to the little endian representation of value. The size of the transaction must not exceed 8 for this function to be used. Similarly, SIM_set_transaction_value_be sets the transaction bytes to the big endian representation of the provided value. If the transaction is smaller than 8 bytes the functions will truncate the representation of the value.

The SIM_set_transaction_bytes_constant function can be used when an endpoint wants to set all transaction bytes to value.

EXECUTION CONTEXT
Cell Context

SIM_transaction_flags()

NAME
SIM_transaction_flags, SIM_transaction_is_fetch, SIM_transaction_is_write, SIM_transaction_is_read, SIM_transaction_is_inquiry — return transaction type
SYNOPSIS
transaction_flags_t
SIM_transaction_flags(const transaction_t *NOTNULL t);

bool
SIM_transaction_is_fetch(const transaction_t *NOTNULL t);

bool
SIM_transaction_is_write(const transaction_t *NOTNULL t);

bool
SIM_transaction_is_read(const transaction_t *NOTNULL t);

bool
SIM_transaction_is_inquiry(const transaction_t *NOTNULL t);

DESCRIPTION
SIM_transaction_flags returns a transaction_flags_t bitmap describing transaction type. Most of the flags can be queried using specific accessors.

The SIM_transaction_is_fetch function returns true if the transaction is an instruction fetch.

The SIM_transaction_is_read function returns true if the transaction is a read operation.

The SIM_transaction_is_write function returns true if the transaction is a write operation.

The SIM_transaction_is_inquiry function returns true if the transaction is an inquiry operation.

EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_transaction_initiator()

NAME
SIM_transaction_initiator — return transaction initiator
SYNOPSIS
conf_object_t *
SIM_transaction_initiator(const transaction_t *t);

DESCRIPTION
Return the initiator of the transaction.
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_transaction_is_deferrable()

NAME
SIM_transaction_is_deferrable — check if a transaction can be deferred for later completion
SYNOPSIS
bool
SIM_transaction_is_deferrable(const transaction_t *NOTNULL t);

DESCRIPTION
The function allows to check whether a transaction can be deferred (with the SIM_defer_transaction or SIM_defer_owned_transaction function) for later completion which is done with a call to SIM_complete_transaction.

Usually, this function is not needed since SIM_defer_transaction and SIM_defer_owned_transaction return NULL for transactions that cannot be deferred.

RETURN VALUE
false if the transaction was issued synchronously and cannot be deferred. Otherwise, true. When a transaction cannot be deferred, endpoint's issue method of the transaction interface may choose to return the error status Sim_PE_Async_Required.
EXECUTION CONTEXT
Cell Context

SIM_transaction_size()

NAME
SIM_transaction_size — return transaction size
SYNOPSIS
unsigned
SIM_transaction_size(const transaction_t *NOTNULL t);

DESCRIPTION
Return the size of the transaction, in bytes.
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_transaction_wait()

NAME
SIM_transaction_wait — wait for transaction completion
SYNOPSIS
exception_type_t
SIM_transaction_wait(transaction_t *t, exception_type_t ex);

DESCRIPTION
SIM_transaction_wait waits until an issued transaction has completed.

The function may only be invoked for transactions which have a completion atom containing a NULL pointer. The NULL pointer means that the initiator will wait for transaction completion using this function. Moreover, SIM_transaction_wait must always be called after a transaction has been issued with a NULL completion callback.

The ex argument should be the return value of the function or method used to issue the transaction.

SIM_transaction_wait will not return until the transaction has completed. While waiting, a different user-level thread will be activated, which allows simulated time to advance.

Note that checkpointing is not possible while waiting for a transaction to complete using this function. Moreover, transaction wait is not supported from all contexts. When unsupported, the transaction will appear to be issued synchronously.

RETURN VALUE
Completion status of the transaction
EXECUTION CONTEXT
Cell Context

Memory Transactions

SIM_arm_mem_trans_from_generic()

NAME
SIM_arm_mem_trans_from_generic, SIM_mips_mem_trans_from_generic, SIM_ppc_mem_trans_from_generic, SIM_x86_mem_trans_from_generic, SIM_pci_mem_trans_from_generic — convert generic transaction to CPU specific
SYNOPSIS
struct arm_memory_transaction *
SIM_arm_mem_trans_from_generic(generic_transaction_t *NOTNULL mop);

struct mips_memory_transaction *
SIM_mips_mem_trans_from_generic(generic_transaction_t *NOTNULL mop);

struct ppc_memory_transaction *
SIM_ppc_mem_trans_from_generic(generic_transaction_t *NOTNULL mop);

struct x86_memory_transaction *
SIM_x86_mem_trans_from_generic(generic_transaction_t *NOTNULL mop);

struct pci_memory_transaction *
SIM_pci_mem_trans_from_generic(generic_transaction_t *NOTNULL mop);

DESCRIPTION
Converts a pointer to a generic memory transaction into a pointer to a CPU specific memory transaction. The generic memory transaction must be part of a CPU specific one for this function to succeed. The pointer returned will be the same the input pointer if conversion is allowed, and NULL on failure.
EXCEPTIONS
SimExc_Type Thrown if the generic transaction is not part of a CPU specific transaction.

RETURN VALUE
New memory transaction pointer, or NULL on error.

EXECUTION CONTEXT
Cell Context

SIM_c_get_mem_op_value_buf()

NAME
SIM_c_get_mem_op_value_buf, SIM_get_mem_op_value_buf, SIM_get_mem_op_value_cpu, SIM_get_mem_op_value_le, SIM_get_mem_op_value_be — get value for a memory operation
SYNOPSIS
void
SIM_c_get_mem_op_value_buf(const generic_transaction_t *NOTNULL mop,
                           uint8 *NOTNULL dst);

attr_value_t
SIM_get_mem_op_value_buf(const generic_transaction_t *NOTNULL mop);

uint64
SIM_get_mem_op_value_cpu(const generic_transaction_t *NOTNULL mop);

uint64
SIM_get_mem_op_value_le(const generic_transaction_t *NOTNULL mop);

uint64
SIM_get_mem_op_value_be(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Returns load or store value for a memory transaction. If the data size is 8 bytes or less the SIM_get_mem_op_value_be and SIM_get_mem_op_value_le functions can be used. For reads/writes larger than 8 bytes, the functions SIM_c_get_mem_op_value_buf or SIM_get_mem_op_value_buf should be used to get the data.

If your model is compiled with one of the DEVICE_IS_LITTLE_ENDIAN, DEVICE_IS_BIG_ENDIAN pre-processor defines, then the SIM_get_mem_op_value function can be used as an alias to the SIM_get_mem_op_value_le and SIM_get_mem_op_value_be versions.

The SIM_c_get_mem_op_value_buf function is only available from C/C++. It places the data into the buffer pointed to by dst. No endian conversion is performed, i.e. data is returned in target endianness. There is no alignment requirement on the dst parameter.

WARNING
When called from a memory-hierarchy (timing-model) only store values can be retrieved, since the load has not yet performed. To get the load value, a snoop-device should be used.
RETURN VALUE
SIM_c_get_mem_op_value_buf returns nothing. The out parameter dst is filled with the data buffer of the memory transaction. SIM_get_mem_op_value_buf returns an attr_value_t (type data) containing the data buffer of the memory transaction. SIM_get_mem_op_value_be returns the zero-extended value in host endian order (interpreted as big endian) for the memory transaction. SIM_get_mem_op_value_le returns the zero-extended value in host endian order (interpreted as little endian). SIM_get_mem_op_value_cpu interprets the data in the default endian order for the initiating processor. This function can only be used for processor initiated memory operations. It is recommended that one of the other functions are used instead.

EXCEPTIONS
SimExc_Memory Thrown if the size of the operation is illegal.

EXECUTION CONTEXT
Cell Context

SIM_c_set_mem_op_value_buf()

NAME
SIM_c_set_mem_op_value_buf, SIM_set_mem_op_value_buf, SIM_set_mem_op_value_cpu, SIM_set_mem_op_value_le, SIM_set_mem_op_value_be — set value for a memory operation
SYNOPSIS
void
SIM_c_set_mem_op_value_buf(generic_transaction_t *NOTNULL mop,
                           const uint8 *NOTNULL src);

void
SIM_set_mem_op_value_buf(generic_transaction_t *NOTNULL mop,
                         attr_value_t value);

void
SIM_set_mem_op_value_cpu(generic_transaction_t *NOTNULL mop, uint64 value);

void
SIM_set_mem_op_value_le(generic_transaction_t *NOTNULL mop, uint64 value);

void
SIM_set_mem_op_value_be(generic_transaction_t *NOTNULL mop, uint64 value);

DESCRIPTION
Set the value returned to the requester of a memory operation. If the data size is 8 bytes or less the SIM_set_mem_op_value_be and SIM_set_mem_op_value_le functions can be used. For sizes larger than 8 bytes, the functions SIM_c_set_mem_op_value_buf or SIM_set_mem_op_value_buf should be used to set the data as an attr_value_t of data type.

If your model is compiled with one of the DEVICE_IS_LITTLE_ENDIAN, DEVICE_IS_BIG_ENDIAN pre-processor defines, then the SIM_set_mem_op_value function can be used as an alias to the SIM_set_mem_op_value_le and SIM_set_mem_op_value_be versions.

SIM_c_set_mem_op_value_buf is only available from C/C++, it operates on data in target endian order. There is no alignment requirement on the buf parameter.

SIM_set_mem_op_value_be takes data in host endian order and sets it in big-endian.

SIM_set_mem_op_value_le takes data in host endian order and sets it in little-endian.

SIM_set_mem_op_value_cpu takes data in host endian order and sets it in the default endian order for the initiating processor. This function can only be used for processor initiated memory operations. It is recommended that one of the other functions are used instead.

The functions that set the memory operation based on a value will truncate the representation of that value if the memory operation is smaller than 8 bytes.

WARNING
These functions cannot be called from a timing-model since the real operation will overwrite the value set. They should instead be used from a snoop-device.
EXCEPTIONS
SimExc_Memory Thrown if the size of the operation is illegal.

EXECUTION CONTEXT
Cell Context

SIM_get_mem_op_page_cross()

NAME
SIM_get_mem_op_page_cross — detect transaction split
SYNOPSIS
FORCE_INLINE unsigned
SIM_get_mem_op_page_cross(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
If a memory transaction was split because it straddled an MMU page, return 1 if it is the first part and 2 for the second. If the transaction was not split, return zero.
EXECUTION CONTEXT
Cell Context

SIM_get_mem_op_size()

NAME
SIM_get_mem_op_size — get transaction size
SYNOPSIS
FORCE_INLINE unsigned
SIM_get_mem_op_size(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve the size, in bytes, of a memory transaction.
EXECUTION CONTEXT
Cell Context

SIM_get_mem_op_type()

NAME
SIM_get_mem_op_type — get type of transaction
SYNOPSIS
FORCE_INLINE mem_op_type_t
SIM_get_mem_op_type(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
This function returns the type of the memory transaction.
SEE ALSO
generic_transaction_t, SIM_set_mem_op_type
EXECUTION CONTEXT
Cell Context

SIM_get_mem_op_type_name()

NAME
SIM_get_mem_op_type_name — get name of memory operation type
SYNOPSIS
const char *
SIM_get_mem_op_type_name(mem_op_type_t type);

DESCRIPTION
Returns a string describing type or NULL if unknown.
EXECUTION CONTEXT
Cell Context

SIM_make_mem_op_write()

NAME
SIM_make_mem_op_write, SIM_make_mem_op_read — create a memory transaction
SYNOPSIS
generic_transaction_t
SIM_make_mem_op_write(physical_address_t addr, bytes_t data,
                      bool inquiry, conf_object_t *initiator);

generic_transaction_t
SIM_make_mem_op_read(physical_address_t addr, buffer_t buffer,
                     bool inquiry, conf_object_t *initiator);

DESCRIPTION
Create and return a memory transaction for writing data to addr, or reading from addr into buffer. The number of bytes to transfer is specified by data and buffer respectively. The initiator is the object issuing the transaction; it may be NULL.

These functions do not actually perform any memory operation; they just construct the generic_transaction_t that can be used in other calls.

The buffer argument must refer to an allocated buffer, and data must contain valid data. They must remain valid and allocated during the life-time of the returned value.

EXECUTION CONTEXT
Cell Context

SIM_mem_op_ensure_future_visibility()

NAME
SIM_mem_op_ensure_future_visibility — request transaction visibility
SYNOPSIS
FORCE_INLINE void
SIM_mem_op_ensure_future_visibility(generic_transaction_t *NOTNULL mop);

DESCRIPTION
Request that future accesses from the same virtual address (using a granularity given by the min_cacheline_size processor attribute) will be seen by the memory hierarchy. Otherwise, the simulator may cache accesses to this address for performance so that they are not seen by the memory model.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_atomic()

NAME
SIM_mem_op_is_atomic — detect transaction atomicity
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_atomic(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Return true if the transaction was part of an atomic instruction (usually a read followed by a write), false otherwise.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_control()

NAME
SIM_mem_op_is_control — transaction control predicates
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_control(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Checks whether mem_op is a control transaction (one that does not actually transfer any data, such as cache control operations).
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_data()

NAME
SIM_mem_op_is_data, SIM_mem_op_is_instruction — transaction data/instruction predicates
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_data(const generic_transaction_t *NOTNULL mop);

FORCE_INLINE bool
SIM_mem_op_is_instruction(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
These functions check whether mem_op is a data or an instruction transaction. Currently, the only transactions that are instruction transactions are instruction fetches.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_from_cache()

NAME
SIM_mem_op_is_from_cache — Cache initiated transaction
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_from_cache(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Checks whether mem_op is sent from a cache timing model.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_from_cpu()

NAME
SIM_mem_op_is_from_cpu — CPU initiated transaction
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_from_cpu(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Checks whether mem_op is sent from a processor.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_from_cpu_arch()

NAME
SIM_mem_op_is_from_cpu_arch — CPU initiated transaction
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_from_cpu_arch(const generic_transaction_t *NOTNULL mop,
                            ini_type_t arch);

DESCRIPTION
Checks whether mem_op is sent from a processor of a specific architecture.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_from_device()

NAME
SIM_mem_op_is_from_device — Device initiated transaction
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_from_device(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Checks whether mem_op is sent from a device.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_prefetch()

NAME
SIM_mem_op_is_prefetch — transaction control predicates
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_prefetch(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Checks whether mem_op is prefetch transaction.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_is_read()

NAME
SIM_mem_op_is_read, SIM_mem_op_is_write — transaction read/write predicates
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_is_read(const generic_transaction_t *NOTNULL mop);

FORCE_INLINE bool
SIM_mem_op_is_write(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
These functions check whether mem_op is a read or a write transaction.
EXECUTION CONTEXT
Cell Context

SIM_mem_op_may_stall()

NAME
SIM_mem_op_may_stall — detect transaction stall possibility
SYNOPSIS
FORCE_INLINE bool
SIM_mem_op_may_stall(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
If true, the simulator will allow the transaction to stall execution. When false, a memory hierarchy must not attempt any stalling.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_exception()

NAME
SIM_set_mem_op_exception, SIM_get_mem_op_exception — get/set transaction exception
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_exception(generic_transaction_t *NOTNULL mop,
                         exception_type_t exc);

FORCE_INLINE exception_type_t
SIM_get_mem_op_exception(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve or change the transaction exception. If set to a value other than Sim_PE_No_Exception, the transaction will be interrupted and an exception will be taken.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_initiator()

NAME
SIM_set_mem_op_initiator, SIM_get_mem_op_initiator, SIM_get_mem_op_ini_type — get/set transaction initiator
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_initiator(generic_transaction_t *NOTNULL mop,
                         ini_type_t type, conf_object_t *obj);

FORCE_INLINE conf_object_t *
SIM_get_mem_op_initiator(const generic_transaction_t *NOTNULL mop);

FORCE_INLINE ini_type_t
SIM_get_mem_op_ini_type(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve or change the transaction initiator type and object. These two parameters must agree.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_inquiry()

NAME
SIM_set_mem_op_inquiry, SIM_get_mem_op_inquiry — get/set transaction inquiry flag
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_inquiry(generic_transaction_t *NOTNULL mop, bool inquiry);

FORCE_INLINE bool
SIM_get_mem_op_inquiry(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve or change the transaction inquiry flag. An inquiry read has no side-effects. An inquiry write has no other side-effect than changing the bytes at the specified address and size.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_physical_address()

NAME
SIM_set_mem_op_physical_address, SIM_get_mem_op_physical_address, SIM_set_mem_op_virtual_address, SIM_get_mem_op_virtual_address — get or set transaction address
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_physical_address(generic_transaction_t *NOTNULL mop,
                                physical_address_t pa);

FORCE_INLINE physical_address_t
SIM_get_mem_op_physical_address(const generic_transaction_t *NOTNULL mop);

FORCE_INLINE void
SIM_set_mem_op_virtual_address(generic_transaction_t *NOTNULL mop,
                               logical_address_t va);

FORCE_INLINE logical_address_t
SIM_get_mem_op_virtual_address(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve or set the physical or virtual (logical) addresses of a memory transaction.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_reissue()

NAME
SIM_set_mem_op_reissue — request transaction reissue
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_reissue(generic_transaction_t *NOTNULL mop);

DESCRIPTION
Request that the transaction will be re-issued if a non-zero stall time is returned from a memory hierarchy. Otherwise, the memory model will not see the transaction again.
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_type()

NAME
SIM_set_mem_op_type — set type of transaction
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_type(generic_transaction_t *NOTNULL mop, mem_op_type_t type);

DESCRIPTION
This function sets the type of the memory transaction.
SEE ALSO
generic_transaction_t, SIM_get_mem_op_type
EXECUTION CONTEXT
Cell Context

SIM_set_mem_op_user_data()

NAME
SIM_set_mem_op_user_data, SIM_get_mem_op_user_data — get/set transaction user data
SYNOPSIS
FORCE_INLINE void
SIM_set_mem_op_user_data(generic_transaction_t *NOTNULL mop,
                         void *data);

FORCE_INLINE void *
SIM_get_mem_op_user_data(const generic_transaction_t *NOTNULL mop);

DESCRIPTION
Retrieve or change user data associated with the transaction. This data is not touched by Simics in any way and its handling and interpretation is left to the user. It can be used to pass information from a timing model to a snoop device, but the data does not survive across a stall.
EXECUTION CONTEXT
Cell Context

Device Translators

SIM_free_map_target()

NAME
SIM_free_map_target — free a map target
SYNOPSIS
void
SIM_free_map_target(map_target_t *mt);

DESCRIPTION
Releases a map target and all associated resources.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_new_map_target

SIM_map_target_flush()

NAME
SIM_map_target_flush — ensure that old translations are not used
SYNOPSIS
bool
SIM_map_target_flush(const map_target_t *NOTNULL mt,
                     uint64 base, uint64 size, access_t access);

DESCRIPTION
This API function is intended to be used for the implementation the translation_flush interface. The documentation for the translation_flush interface describes how to use this function for the interface implementation.

Additionally, this function can be used as a replacement for the SIM_translation_changed function to do a more fine-grain invalidation in the case when a previously returned translation becomes invalid.

When a previously returned translation becomes invalid the translator object should notify Simics which can have translations cached. To notify Simics the translator object can either do the call to the SIM_translation_changed function or, as a potential performance optimization, do a more fine-grain invalidation by using the SIM_map_target_flush function.

The translator object is expected to call the SIM_map_target_flush function for all targets of all previously returned translations which became invalid. If there are too many translations which are to be invalidated, then, performance-wise, it may be better just to do a single call to the SIM_translation_changed function. Also, if, during invalidation, any of the calls to the SIM_map_target_flush fails (i.e. the false value is returned by the function) then the translator is expected to call the SIM_translation_changed function which always succeeds.

Please note that there is no need to call the SIM_map_target_flush function for the translations which were tagged with the Sim_Translation_Dynamic flag. Either, no invalidation is needed for the destinations where nothing is mapped.

EXECUTION CONTEXT
Cell Context

SIM_map_target_object()

NAME
SIM_map_target_object, SIM_map_target_port, SIM_map_target_target — inspect a map target
SYNOPSIS
conf_object_t *
SIM_map_target_object(const map_target_t *NOTNULL mt);

const char *
SIM_map_target_port(const map_target_t *NOTNULL mt);

const map_target_t *
SIM_map_target_target(const map_target_t *NOTNULL mt);

DESCRIPTION
Helper functions allowing inspection of the map_target_t objects.
RETURN VALUE
Returns a Simics object, port, or chained target which was used for the creation of the mt map target, i.e., the respective argument passed to SIM_new_map_target when the map target was created.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_new_map_target

SIM_new_map_target()

NAME
SIM_new_map_target — create a map target
SYNOPSIS
map_target_t *
SIM_new_map_target(conf_object_t *NOTNULL obj, const char *port,
                   const map_target_t *chained_target);

DESCRIPTION
Create and return a new map target. A map target can be viewed as an opaque representation of an object/interface pair which can function either as an endpoint for a memory transaction or as an address space where a memory transaction can be performed.

Map targets are usually used in conjunction with the translator interface and can represent anything which is mappable in a memory space, e.g., IO banks, RAM, ROM, memory spaces, port spaces, bridges, or translators. In order to get better performance, we recommend to allocate a map target once and reuse it rather than to allocate and delete it every time.

If the chained_target parameter is null, obj is searched for one of the following interfaces: ram, rom, io_memory, port_space, translator, transaction_translator, transaction or memory_space. The interfaces are tried in the listed order, and the first interface found determines the "type" of the map target. For example, if obj implements both the io_memory and the translator interface, then the created map target will direct memory transactions to the io_memory interface.

If a map target argument is passed in the chained_target parameter, then obj must implement one of the following interfaces: translator, bridge, or translate. The chained target contains information about a secondary map target used either directly or indirectly by the interface. For objects implementing the translator interface, the chained target is passed as an argument to the translate method. For bridges, the chained target is the target which is accessed through the bridge. For objects implementing translate, the chained target is used as the target of the translation if the translate method returns null.

Note: Information about the chained target is encoded in the created map target, but no direct references are kept to the argument. In other words, ownership is not transferred by this call and the caller is responsible for releasing chained_target as appropriate.

If a string is passed in the port parameter, then Simics looks for port interfaces instead of regular interfaces.

RETURN VALUE
Returns a map target, encoding information about the object, the interface, and the chained target, if any. NULL is returned if an exception was thrown.
EXCEPTIONS
SimExc_Lookup Thrown if no usable port interface was found.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_free_map_target, map_target_t, SIM_map_target_object, translator_interface_t

SIM_translation_changed()

NAME
SIM_translation_changed — ensure that old translations are not used
SYNOPSIS
void
SIM_translation_changed(conf_object_t *NOTNULL obj);

DESCRIPTION
Devices implementing the translator interface need to call this function whenever a previously returned translation becomes invalid; the only exception is if all invalid translations were tagged with Sim_Translation_Dynamic, in which case this is not necessary.

Failure to call this function will likely result in Simics continuing to use old translations, since those may have been cached internally.

The object implementing the translator should be passed in the obj parameter.

EXECUTION CONTEXT
Cell Context
SEE ALSO
translator_interface_t

Time and Events

SIM_cycle_count()

NAME
SIM_cycle_count — read cycle counter
SYNOPSIS
cycles_t  
SIM_cycle_count(conf_object_t *NOTNULL obj);

DESCRIPTION
SIM_cycle_count returns the current simulated clock cycle count at obj.

If obj is a cycle counter implementing either the cycle_event interface or the cycle interface, then the returned count is the number of elapsed cycles according to that object. If obj is not a cycle counter, then the default clock associated with the object is queried for its cycle count.

SEE ALSO
SIM_object_clock
RETURN VALUE
SIM_cycle_count returns the current time in number of cycles.
EXECUTION CONTEXT
Cell Context

SIM_event_cancel_time()

NAME
SIM_event_cancel_time, SIM_event_cancel_step — cancel an event before expiration
SYNOPSIS
void
SIM_event_cancel_time(conf_object_t *NOTNULL clock,
                      event_class_t *NOTNULL evclass,
                      conf_object_t *NOTNULL obj,
                      int (*pred)(lang_void *data, lang_void *match_data),
                      lang_void *match_data);

void
SIM_event_cancel_step(conf_object_t *NOTNULL clock,
                      event_class_t *NOTNULL evclass,
                      conf_object_t *NOTNULL obj,
                      int (*pred)(lang_void *data, lang_void *match_data),
                      lang_void *match_data);

DESCRIPTION
All unexpired evclass events posted for obj on clock for which pred returns nonzero will be cancelled and their destructor methods (if any) called. pred will be called with the data associated with the event and the supplied match_data. If pred is null (None in Python), all evclass events for obj on clock will be cancelled.

There are separate calls for events posted at a point in time (cycle or seconds) and on a specific step.

EXCEPTIONS
SimExc_InterfaceNotFound Thrown by SIM_event_cancel_step if the clock object doesn't implement the step interface.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_event, SIM_event_post_time

SIM_event_find_next_cycle()

NAME
SIM_event_find_next_cycle, SIM_event_find_next_time, SIM_event_find_next_step — find event expiration time
SYNOPSIS
cycles_t
SIM_event_find_next_cycle(conf_object_t *NOTNULL clock,
                          event_class_t *NOTNULL evclass,
                          conf_object_t *NOTNULL obj,
                          int (*pred)(lang_void *data, lang_void *match_data),
                          lang_void *match_data);

double
SIM_event_find_next_time(conf_object_t *NOTNULL clock,
                         event_class_t *NOTNULL evclass,
                         conf_object_t *NOTNULL obj,
                         int (*pred)(lang_void *data, lang_void *match_data),
                         lang_void *match_data);

pc_step_t
SIM_event_find_next_step(conf_object_t *NOTNULL clock,
                         event_class_t *NOTNULL evclass,
                         conf_object_t *NOTNULL obj,
                         int (*pred)(lang_void *data, lang_void *match_data),
                         lang_void *match_data);

DESCRIPTION
Return the number of cycles/seconds/steps to the first event of evclass of obj posted on clock for which pred is true, or −1 if no event matched. pred will be called with the data associated with the event and the supplied match_data. If pred is null (None in Python), the first evclass event for obj on clock will be used.

There are separate calls of events posted at a point in time (cycle or seconds) and on a specific step. Note that the return value of SIM_event_find_next_cycle is only a preliminary estimate; the number of remaining cycles will change if the clock's frequency changes dynamically. To handle dynamically changing clock frequencies correctly, subscribe to the frequency changes via the clock's simple_dispatcher interface.

EXCEPTIONS
SimExc_InterfaceNotFound Thrown by SIM_event_find_next_step if the clock object doesn't implement the step interface: Minus one is returned in such a case.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_event, SIM_event_post_time

SIM_event_post_time()

NAME
SIM_event_post_time, SIM_event_post_cycle, SIM_event_post_step — post an event
SYNOPSIS
void 
SIM_event_post_time(conf_object_t *NOTNULL clock,
                    event_class_t *NOTNULL evclass,
                    conf_object_t *NOTNULL obj,
                    double seconds,
                    lang_void *user_data);

void
SIM_event_post_cycle(conf_object_t *NOTNULL clock,
                     event_class_t *NOTNULL evclass,
                     conf_object_t *NOTNULL obj,
                     cycles_t cycles,
                     lang_void *user_data);

void
SIM_event_post_step(conf_object_t *NOTNULL clock,
                    event_class_t *NOTNULL evclass,
                    conf_object_t *NOTNULL obj,
                    pc_step_t steps,
                    lang_void *user_data);

DESCRIPTION
An event of evclass for object obj is posted on clock to occur at a given point in the future. The user_data will be associated with the event.

The clock is the object that should be used for keeping track of time for the event. It can be a processor or an instance of the clock class.

If a configuration class was specified when evclass was registered, then obj must be an instance of that class.

The expiration point can be specified in seconds, cycles or steps by using the appropriate call, and these values are relative to the current state. Events that need to run synchronized (Sim_EC_Machine_Sync) can only be posted in seconds or cycles, not steps, since synchronization can only be perform in virtual time.

Note: Events posted with SIM_event_post_cycle are posted at a certain point in time based on the clock's current frequency, not at a certain clock cycle. The difference is significant if the frequency of the clock object can change dynamically.
EXCEPTIONS
SimExc_InterfaceNotFound
Thrown by SIM_event_post_step if the clock object doesn't implement the step interface.
SimExc_General
Thrown if the number of steps or time is negative or too far ahead, and, for Sim_EC_Machine_Sync events, if the event is posted less than a time quantum in the future.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_event, SIM_event_cancel_time

SIM_register_event()

NAME
SIM_register_event — register an event
SYNOPSIS
event_class_t *
SIM_register_event(
               const char *NOTNULL name,
               conf_class_t *cl,
               event_class_flag_t flags,
               void (*NOTNULL callback)(conf_object_t *obj, lang_void *data),
               void (*destroy)(conf_object_t *obj, lang_void *data),
               attr_value_t (*get_value)(conf_object_t *obj, lang_void *data),
               lang_void *(*set_value)(conf_object_t *obj, attr_value_t value),
               char *(*describe)(conf_object_t *obj, lang_void *data));

DESCRIPTION
Registers events identified by name and to be posted for objects of class cl, and returns the event class to be used in other calls. The supplied methods are:

callback
Called when the event expires.
destroy
Called when the event is removed from the queue without being called. The method is not allowed to use any event API calls; it is mainly intended for freeing event data. May be null.
get_value
Called to convert the event data into a value that can be saved in a configuration. May be null when the event carries no data of interest.
set_value
Called to convert a configuration value into event data. May be null when the event carries no data of interest.
describe
Called to generate a human-readable description of the event to be used in the print-event-queue command. If written in C, must return an allocated string (using MM_MALLOC or MM_STRDUP). May be null, in which case the name is used.

Null function pointers correspond to the value None when invoked from Python.

The flags is typically either zero or Sim_EC_Notsaved, where Sim_EC_Notsaved indicates that the event should not be saved as part of the configuration. In that case, get_value and set_value must both be null, and cl may then also be null. The other flag bits defined in the event_class_flag_t are reserved for internal use in the Simics platform and some tightly coupled modules. See the event queue sample code for details of their use.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_event_post_time

SIM_run_unrestricted()

NAME
SIM_run_unrestricted — run callback after current instruction
SYNOPSIS
void
SIM_run_unrestricted(conf_object_t *NOTNULL obj,
                     void (*NOTNULL func)(conf_object_t *obj,
                                          lang_void *param),
                     lang_void *user_data);

DESCRIPTION
The func functions will be called immediately, if Simics is not currently running an instruction, or as soon as the current instruction has completed.

Note that with the introduction of Multicore Accelerator, if an instruction is running when calling SIM_run_unrestricted, other simulation threads may continue for a while until they stop and the callback is serviced. This means that an object using SIM_run_unrestricted may receive calls through for example the io_memory interface after returning from the scope where SIM_run_unrestricted is called but before the func callback function is called. For more information on considerations for Multicore Accelerator, see the Simics Model Builder User's Guide.

If several functions are registered this way before any of them has had a chance to run, the functions will be run in their order of registration.

This call is mainly useful for actions that for various reasons can not be done while an instruction is being emulated.

The obj is an object that has a clock (as defined by SIM_object_clock). This object and user_data are passed to the callback function.

Since the callback is run in Cell Context, simulation threads for other cells may be running when the callback is executed. Consequently, only objects in the same cell as obj may be accessed from the callback.

SEE ALSO
SIM_run_alone
EXECUTION CONTEXT
All contexts including Threaded Context (call); Cell Context (callback)

SIM_step_count()

NAME
SIM_step_count — get step count
SYNOPSIS
pc_step_t
SIM_step_count(conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the number of steps executed by the processor obj. A step is a completed instruction, an instruction causing a synchronous exception, or an asynchronous exception (interrupt).
EXCEPTIONS
SimExc_InterfaceNotFound Thrown if the obj object doesn't implement the step interface. Minus one is returned in such a case.

EXECUTION CONTEXT
Cell Context

SIM_time()

NAME
SIM_time — get current simulated time
SYNOPSIS
double
SIM_time(conf_object_t *NOTNULL obj);

DESCRIPTION
SIM_time returns the current time at obj.

The returned time relates to how long the simulation has been running, and is usually not very useful in itself, but it can be used to compare with other times. The time on a specific processor is guaranteed to increase when simulation progresses, even if the clock frequency is changed. When adding a processor, it is assigned a current time to be synchronized with other processors in the simulation, or the time 0.0 if it is the first processor.

Note: The precision of the returned value degrades significantly with simulated time due to its representation as a double. When absolute timestamps are needed for the actual simulation, it is recommended that the SIM_cycle_count function is used instead on the picosecond clock.
Note: Using SIM_time on the picosecond clock will currently give the same result as SIM_time on the default clock. That is, the precision of this API function is limited by the frequency of the default clock.
SEE ALSO
SIM_picosecond_clock
RETURN VALUE
SIM_time returns the current time in seconds as a floating point value.
EXECUTION CONTEXT
Cell Context

Version and Copyrights

SIM_register_copyright()

NAME
SIM_register_copyright — register copyright information
SYNOPSIS
void
SIM_register_copyright(const char *NOTNULL str);

DESCRIPTION
This registers specific copyright information related to an extension module or similar component of Simics. The Simics front-end command "copyright" will list, in addition to Simics copyright notices, any registered notices from libraries or plug-ins that have added a string using this function.

The string should contain only standard ASCII characters, be pre-formatted for at most 80-character width terminal, be non-indented, and have no spurious new-line characters before or after the last line (except for the new-line that marks the end of the last line).

The string will not be copied so needs to be either static or a copy generated by the callee (preferably static).

EXECUTION CONTEXT
Global Context

SIM_version()

NAME
SIM_version, SIM_version_base, SIM_version_major, SIM_license, SIM_license_file, SIM_copyright, SIM_vmxmon_version — get Simics version and license/copyright information
SYNOPSIS
const char *
SIM_version(void);

const char *
SIM_version_base(void);

const char *
SIM_version_major(void);

void
SIM_license(void);

char *
SIM_license_file(const char *format);

char *
SIM_copyright(void);

char *
SIM_vmxmon_version(void);

DESCRIPTION
SIM_version
returns the version of all installed Simics products.
SIM_version_base
returns the version of the Simics base package only.
SIM_version_major
returns the current major version of Simics.
SIM_vmxmon_version
returns the version of the VMP kernel module loaded on the host machine. NULL is returned if the module is not loaded.
SIM_license_file
returns the filename of the currently applying License Agreement (SLA/EULA), if any is found. The format parameter can be either an empty string (text version) or "rtf" (RTF version).
returns the copyright notice for Simics.
SIM_license
doesn't return anything but prints out a short text describing licensing conditions.

SIM_version, SIM_version_base, SIM_version_major return a string owned by Simics. These strings must not be deallocated or modified by the caller.

SIM_vmxmon_version, SIM_license_file, and SIM_copyright return a newly allocated string which is owned by the caller. This means that when the function is called from C its return value should be later freed with the use of the MM_FREE macro.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_register_copyright

3.3.1 frags_t

The frags_t data type is part of the Simics API. It is used to manipulate and modify network packets inside models efficiently. It is meant to replace DBuffer in network device models wherever appropriate. See the Model Builder User's Guide for an introduction to programming with frags_t.

Function List

frags_add()

NAME
frags_add — add data to a frags_t
SYNOPSIS
FORCE_INLINE void
frags_add(frags_t *buf, const void *data, size_t len);

DESCRIPTION
Append the new data data of size len to buf. A frags_t can hold up to 8 data fragments.
RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 new_data[2] = { 7, 8 };
frags_add(&foo, new_data, sizeof(new_data));

SEE ALSO
frags_init_add, frags_init_add_from_frags, frags_add_from_frags

frags_add_from_frags()

NAME
frags_add_from_frags — append an existing frags_t to another
SYNOPSIS
FORCE_INLINE void
frags_add_from_frags(frags_t *dst, const frags_t *src,
                     size_t offset, size_t len);

DESCRIPTION
Append len bytes of the data at offset offset in src to dst.
RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
frags_add_from_frags(&foo, &bar, 4, frags_len(&bar) - 4);

SEE ALSO
frags_init_add, frags_add, frags_init_add_from_frags

frags_extract()

NAME
frags_extract — extract the contents of a frags_t
SYNOPSIS
void frags_extract(const frags_t *buf, void *vdst);

DESCRIPTION
Copy the whole contents of buf to vdst. The destination buffer vdst should be large enough to contain all data in buf.

This function is completely equivalent to frags_extract_slice() with an offset and a length covering the whole contents of the frags_t, and is provided for convenience.

RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 all_data[frags_len(&foo)];
frags_extract(&foo, all_data);

SEE ALSO
frags_extract_8, frags_extract_slice, frags_extract_alloc, frags_extract_slice_alloc

frags_extract_8()

NAME
frags_extract_8, frags_extract_be16, frags_extract_le16, frags_extract_be32, frags_extract_le32, frags_extract_be64, frags_extract_le64 — extract a value
SYNOPSIS
uint8 frags_extract_8(const frags_t *buf, size_t offset);

uint16 frags_extract_be16(const frags_t *buf, size_t offset);

uint16 frags_extract_le16(const frags_t *buf, size_t offset);

uint32 frags_extract_be32(const frags_t *buf, size_t offset);

uint32 frags_extract_le32(const frags_t *buf, size_t offset);

uint64 frags_extract_be64(const frags_t *buf, size_t offset);

uint64 frags_extract_le64(const frags_t *buf, size_t offset);

DESCRIPTION
Extract a 8, 16, 32 or 64 bits value in either big-endian (_be) or little-endian (_le) format from the contents of the frags_t buf at offset offset.
RETURN VALUE
Extracted value
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8  val8  = frags_extract_8(&frame, 1);
uint16 val16 = frags_extract_be16(&frame, 2);
uint32 val32 = frags_extract_le32(&frame, 4);
uint32 val64 = frags_extract_be64(&frame, 8);

SEE ALSO
frags_extract, frags_extract_slice

frags_extract_alloc()

NAME
frags_extract_alloc — return a copy of the contents of a frags_t
SYNOPSIS
void *frags_extract_alloc(const frags_t *buf);

DESCRIPTION
Return an allocated copy of the contents of buf. The buffer returned is allocated with MM_MALLOC(), and its ownership is passed to the caller, which should free it when appropriate.

This function is equivalent to allocating a buffer of the correct size with MM_MALLOC() followed by a call to frags_extract(), and is provided for convenience.

RETURN VALUE
A newly allocated copy of the contents
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 *all = frags_extract_alloc(&foo);
/* ... */
MM_FREE(all);

SEE ALSO
frags_extract, frags_extract_slice, frags_extract_slice_alloc

frags_extract_slice()

NAME
frags_extract_slice — extract a slice of a frags_t
SYNOPSIS
void frags_extract_slice(const frags_t *buf, void *vdst, size_t offset, 
                         size_t len);

DESCRIPTION
Copy a slice of size len, starting at offset offset, of the contents of buf, to vdst. The destination buffer vdst should be able to contain at least len bytes.
RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 some_data[16];
frags_extract_slice(&foo, some_data, 4, 16);

SEE ALSO
frags_extract_8, frags_extract, frags_extract_alloc, frags_extract_slice_alloc

frags_extract_slice_alloc()

NAME
frags_extract_slice_alloc — return a partial copy of the contents of a frags_t
SYNOPSIS
void *frags_extract_slice_alloc(const frags_t *buf, size_t offset, size_t len);

DESCRIPTION
Return an allocated copy of a slice of size len, starting at offset offset, of the contents of buf. The return value is allocated with MM_MALLOC(), and its ownership is passed to the caller, which should free it when appropriate.

This function is equivalent to allocating a buffer of the correct size with MM_MALLOC() followed by a call to frags_extract_slice(), and is provided for convenience.

RETURN VALUE
A newly allocated, partial copy of the data
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 *slice = frags_extract_slice_alloc(&foo, 4, 16);
/* ... */
MM_FREE(slice);

SEE ALSO
frags_extract, frags_extract_slice, frags_extract_alloc

frags_init()

NAME
frags_init — initialize a frags_t
SYNOPSIS
FORCE_INLINE void frags_init(frags_t *buf);

DESCRIPTION
Initialize the frags_t buf. An alternative is to use the FRAGS_INIT constant value.
RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
/* Initialization with frags_init() */
frags_t bar;
frags_init(&bar);

/* Initialization with FRAGS_INIT */
frags_t foo = FRAGS_INIT;

SEE ALSO
frags_init_add

frags_init_add()

NAME
frags_init_add — initialize a frags_t with an initial value
SYNOPSIS
FORCE_INLINE void
frags_init_add(frags_t *buf, const void *data, size_t len);

DESCRIPTION
Initialize the frags_t buf and set it to represent the initial data data of size len.

This function is exactly equivalent to using frags_init(), followed by frags_add(), and is provided for convenience.

RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
frags_t baz;
uint8 data[5] = { 0, 1, 2, 3, 4 };
frags_init_add(&baz, data, sizeof(data));

SEE ALSO
frags_init, frags_add

frags_init_add_from_frags()

NAME
frags_init_add_from_frags — initialize a frags_t from another
SYNOPSIS
FORCE_INLINE void
frags_init_add_from_frags(frags_t *dst, const frags_t *src,
                          size_t offset, size_t len);

DESCRIPTION
Initialize dst and set its initial value to the data of size len starting at offset offset in src.

This function is exactly equivalent to using frags_init(), followed by frags_add_from_frags(), and is provided for convenience.

RETURN VALUE
None
EXECUTION CONTEXT
Cell Context
EXAMPLE
frags_t bat;
ASSERT(frags_len(&foo) > 16);
frags_init_add_from_frags(&bat, &foo, 16, frags_len(&foo) - 16);

SEE ALSO
frags_init_add, frags_add, frags_add_from_frags

frags_it()

NAME
frags_it — return an iterator
SYNOPSIS
FORCE_INLINE frags_it_t
frags_it(const frags_t *buf, size_t offset, size_t len);

DESCRIPTION
Return an iterator on the fragments that compose the data in buf, starting from offset offset and up to a length of len. To iterate on all the data in buf, offset should be set to 0 and len to the value returned by frags_len().
RETURN VALUE
An iterator on the fragments covering the desired data range
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

SEE ALSO
frags_it_end, frags_it_next, frags_it_len, frags_it_data

frags_it_data()

NAME
frags_it_data — return the data of the current fragment
SYNOPSIS
FORCE_INLINE const uint8 *
frags_it_data(frags_it_t it);

DESCRIPTION
Return a pointer to the data of the current fragment pointed by the iterator it.
RETURN VALUE
The data of the current fragment
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

SEE ALSO
frags_it, frags_it_end, frags_it_next, frags_it_len

frags_it_end()

NAME
frags_it_end — return whether an iterator is finished
SYNOPSIS
FORCE_INLINE bool 
frags_it_end(frags_it_t it);

DESCRIPTION
Return true when the iterator it does not have any next fragment to return at the next call of frags_it_next(), and false otherwise.
RETURN VALUE
true if the iterator is finished, false otherwise.
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

SEE ALSO
frags_it, frags_it_next, frags_it_len, frags_it_data

frags_it_len()

NAME
frags_it_len — return the length of the current fragment
SYNOPSIS
FORCE_INLINE size_t
frags_it_len(frags_it_t it);

DESCRIPTION
Return the length of the current fragment pointed by the iterator it.
RETURN VALUE
The length of the current fragment
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

SEE ALSO
frags_it, frags_it_end, frags_it_next, frags_it_data

frags_it_next()

NAME
frags_it_next — return the next fragment's iterator
SYNOPSIS
FORCE_INLINE frags_it_t
frags_it_next(frags_it_t it);

DESCRIPTION
Return an iterator pointing at the next data fragment. This function should only be called if frags_end(it) returns false.
RETURN VALUE
An iterator on the next fragment
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

SEE ALSO
frags_it, frags_it_end, frags_it_len, frags_it_data

frags_len()

NAME
frags_len — return the total data length
SYNOPSIS
FORCE_INLINE size_t frags_len(const frags_t *buf);

DESCRIPTION
Return the total length of the data represented by buf.
RETURN VALUE
The total data length
EXECUTION CONTEXT
Cell Context
EXAMPLE
unsigned len = frags_len(&foo);

frags_prefix()

NAME
frags_prefix — prefix a frags_t with a header
SYNOPSIS
FORCE_INLINE frags_t
frags_prefix(const void *header, size_t header_len, const frags_t *body);

DESCRIPTION
Create a frags_t composed of the header header of size header_len, followed by the contents of the frags_t body.

This function is equivalent to a sequence of frags_init(), frags_add(), frags_add_from_frags() to build a new fragment containing the prefix. It is provided for convenience.

RETURN VALUE
A new frags_t including header and body
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 eth_header[14] = { 0 };
frags_t packet = frags_prefix(eth_header, sizeof(eth_header), &foo);

SEE ALSO
frags_suffix, frags_add_from_frags

frags_suffix()

NAME
frags_suffix — append a suffix to a frags_t
SYNOPSIS
FORCE_INLINE frags_t
frags_suffix(const frags_t *body, void *header, size_t header_len);

DESCRIPTION
Create a frags_t composed of the contents of the frags_t body, followed by the data header of size header_len.

This function is equivalent to a sequence of frags_init(), frags_add_from_frags(), frags_add() to build a new fragment containing the suffix. It is provided for convenience.

RETURN VALUE
A new frags_t including body and header
EXECUTION CONTEXT
Cell Context
EXAMPLE
uint8 eth_checksum[4] = { 0 };
frags_t frame = frags_suffix(&foo, eth_checksum, sizeof(eth_checksum));

SEE ALSO
frags_prefix, frags_add_from_frags

frags_t, frags_it_t

NAME
frags_t, frags_it_t
SYNOPSIS
typedef struct frags frags_t;

typedef struct frags_it frags_it_t;

DESCRIPTION
These types encapsulate a data packet, for use by models that send and receive data, such as network devices.

The structures should never be used directly. Only use the accessor functions.

3.3.2 Dynamic Memory Management

These are routines for manual dynamic memory allocation providing some memory leak detection. They replace the standard C malloc facility in Simics APIs.

Example: to allocate an array of 13 elements of type device_t, use

    device_t *d = MM_MALLOC(13, device_t);

It must be possible to get a pointer to the type by appending an asterisk to the type name; so struct foo * is acceptable, but int (*)(void) is not. Use a typedef in these cases.

It is not possible to mix these calls with the malloc facility for the same allocations.

Macro List

MM_FREE()

NAME
MM_FREE — free allocation
SYNOPSIS
MM_FREE(p);

DESCRIPTION
MM_FREE frees an allocation previously made with MM_MALLOC, MM_MALLOC_SZ, MM_ZALLOC, MM_ZALLOC_SZ, MM_REALLOC, MM_REALLOC_SZ or MM_STRDUP.

A null pointer argument is legal, in which case nothing happens.

MM_MALLOC()

NAME
MM_MALLOC, MM_MALLOC_SZ, MM_ZALLOC, MM_ZALLOC_SZ — allocate memory
SYNOPSIS
MM_MALLOC(nelems, type);

MM_MALLOC_SZ(size, type);

MM_ZALLOC(nelems, type);

MM_ZALLOC_SZ(size, type);

DESCRIPTION
MM_MALLOC allocates nelems objects of type type. MM_MALLOC_SZ specifies the total allocation size in bytes.

MM_ZALLOC and MM_ZALLOC_SZ do the same thing as MM_MALLOC and MM_ZALLOC respectively but in addition fill the allocated memory with null bytes.

If nelems or size are zero, either a null pointer or a pointer to a zero-sized allocation is returned.

RETURN VALUE
Pointer to the allocated object(s).
EXECUTION CONTEXT
All contexts (including Threaded Context)

MM_REALLOC()

NAME
MM_REALLOC, MM_REALLOC_SZ — reallocate memory
SYNOPSIS
MM_REALLOC(p, nelems, type);

MM_REALLOC_SZ(p, size, type);

DESCRIPTION
MM_REALLOC changes the size of an allocated memory block to nelems elements. MM_REALLOC_SZ specifies the new size in bytes.

The allocation must originally have been made by a call to MM_MALLOC, MM_MALLOC_SZ, MM_ZALLOC, MM_ZALLOC_SZ, MM_REALLOC, MM_REALLOC_SZ or MM_STRDUP.

If the passed pointer is null, then these macros are equivalent to an allocation of the desired amount. If nelems or size is zero, either a null pointer or a pointer to a zero-sized allocation is returned, and the original allocation is freed.

The allocation must be freed using MM_FREE.

RETURN VALUE
Pointer to the reallocated object(s).
EXECUTION CONTEXT
All contexts (including Threaded Context)

MM_STRDUP()

NAME
MM_STRDUP — duplicate a string
SYNOPSIS
MM_STRDUP(str);

DESCRIPTION
Allocates and initializes a copy of the null-terminated string str. The allocation must be freed with MM_FREE.
RETURN VALUE
Pointer to the newly allocated string.
EXECUTION CONTEXT
All contexts (including Threaded Context)

3.2 Device API Data Types 3.4 Obsolete Device API Types and Functions