6.1 Simulator API Data Types 7 Simulator-to-Simulator Interfaces
API Reference Manual  /  6 Simulator API  / 

6.2 Simulator API Functions

Breakpoints

SIM_break_cycle()

NAME
SIM_break_cycle — insert breakpoint in time queue
SYNOPSIS
void
SIM_break_cycle(conf_object_t *NOTNULL obj, int64 cycles);

DESCRIPTION
Insert a breakpoint event at cycles clock cycles from now, causing simulation to stop when reached by obj.
EXECUTION CONTEXT
Cell Context

SIM_break_step()

NAME
SIM_break_step — set a step breakpoint
SYNOPSIS
void
SIM_break_step(conf_object_t *NOTNULL obj, int64 steps);

DESCRIPTION
Sets a step breakpoint on a processor. The steps argument is the number of instructions until the break occurs.
EXCEPTIONS
SimExc_InterfaceNotFound Thrown if the obj object doesn't implement the step interface.

EXECUTION CONTEXT
Cell Context

SIM_breakpoint()

NAME
SIM_breakpoint — set breakpoint
SYNOPSIS
breakpoint_id_t
SIM_breakpoint(conf_object_t *NOTNULL obj,
               breakpoint_kind_t kind,
               access_t access,
               uint64 address,
               uint64 length,
               breakpoint_flag_t flags);

DESCRIPTION
Add breakpoint on an object implementing the breakpoint interface. This is typically a memory space object such as physical memory.

Please note that breakpoints set by this function may not appear in the results from <bp-manager>.list . It's recommended to use the bp.memory.break command.

The kind argument sets what type of address to break on:

typedef enum {
        Sim_Break_Physical = 0,
        Sim_Break_Virtual  = 1,
        Sim_Break_Linear   = 2      /* x86 only */
} breakpoint_kind_t;

The access argument is a bit-field setting the type of access. Any combination of the three alternatives can be given (added together).

typedef enum {
        Sim_Access_Read = 1,
        Sim_Access_Write = 2,
        Sim_Access_Execute = 4
} access_t;

The address is the start of the breakpoint range and length is its length in bytes. This range will be truncated as necessary to fit in the address space. An access intersecting the given range will trigger the breakpoint. If length is zero, the breakpoint range will be the entire address space.

The flags argument should be the sum of zero or more enumeration constants from breakpoint_flag_t:

typedef enum breakpoint_flag {
        Sim_Breakpoint_Temporary = 1,
        Sim_Breakpoint_Simulation = 2,
        Sim_Breakpoint_Private = 4
} breakpoint_flag_t;

If the Sim_Breakpoint_Temporary bit is set, the breakpoint is automatically disabled when triggered the first time.

If the Sim_Breakpoint_Simulation bit is set, the breakpoint will not show up in the <bp-manager>.list command, nor can it be removed by the <bp-manager>.delete command. Also, there will be no message printed on the Simics console when this breakpoint is triggered. This bit should be set when using breakpoints to simulate the target system; it will prevent Simics from temporarily disabling the breakpoint as an optimization measure. This could otherwise happen during certain reverse execution operations.

If the Sim_Breakpoint_Private bit is set, the breakpoint will not show up in the <bp-manager>.list command, nor can it be removed by the <bp-manager>.delete command.

The default action for a triggered breakpoint is to return to the frontend (this can be changed by using haps). On execution breakpoints Simics will return to the frontend before the instructions is executed, while instructions triggering read or write breakpoints will complete before control is returned to the frontend.

Several breakpoints can be set on the same address and Simics will break on them in turn. If hap handlers are connected to the breakpoints they will also be executed in turn. Hap handlers are called before the access is performed, allowing the user to read a memory value that may be overwritten by the access. See the Simics Reference Manual for a description of hap handlers.

Several attributes can be set for a breakpoint for breaking only when some conditions are true. See the breakpoints attribute in the sim class.

This function returns the breakpoint id which is used for further reference to the breakpoint:

typedef int breakpoint_id_t;

Breakpoints can be removed using SIM_delete_breakpoint.

EXCEPTIONS
SimExc_General Thrown if the type or access arguments are illegal. Also thrown if obj cannot handle breakpoints of the given kind.

RETURN VALUE
Breakpoint id, -1 on exception.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_breakpoint_remove, SIM_delete_breakpoint

SIM_breakpoint_remove()

NAME
SIM_breakpoint_remove — delete breakpoint range
SYNOPSIS
void
SIM_breakpoint_remove(int id,
                      access_t access,
                      generic_address_t address,
                      generic_address_t length);

DESCRIPTION
Deletes a breakpoint range from an existing breakpoint. Can thus be used to create holes in the breakpoint range. id is the breakpoint to operate on, as returned by SIM_breakpoint. A value of zero will operate on all breakpoints that were not set using the Sim_Breakpoint_Simulation flag.

access is a bitfield describing the type of breakpoint to remove using the enumeration constants of the access_t enum.

address is the start address of the range and length is the length of the range in bytes.

EXCEPTIONS
SimExc_Index Thrown if illegal breakpoint

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_breakpoint, SIM_delete_breakpoint

SIM_delete_breakpoint()

NAME
SIM_delete_breakpoint — delete breakpoint
SYNOPSIS
void
SIM_delete_breakpoint(breakpoint_id_t id);

DESCRIPTION
Deletes breakpoint id as returned by SIM_breakpoint. A value of zero will delete all breakpoints that were set without the Sim_Breakpoint_Simulation flag.
EXCEPTIONS
SimExc_Index Thrown if no breakpoint with the id is found.

EXECUTION CONTEXT
Cell Context

SIM_disable_breakpoint()

NAME
SIM_disable_breakpoint, SIM_enable_breakpoint — disable breakpoint
SYNOPSIS
void
SIM_disable_breakpoint(breakpoint_id_t id);

void
SIM_enable_breakpoint(breakpoint_id_t id);

DESCRIPTION
Enables and disables breakpoint id, as returned by SIM_breakpoint.
EXCEPTIONS
SimExc_Index Thrown if no breakpoint with the id is found.
EXECUTION CONTEXT
Cell Context

Configuration

SIM_add_configuration()

NAME
SIM_add_configuration — set configuration from Python
SYNOPSIS
void
SIM_add_configuration(pre_conf_object_set_t *NOTNULL set,
                      const char *file);

DESCRIPTION
This function creates objects from the parse objects in set and adds the initialized objects to the current configuration (creating one if necessary). When called from Python (which is the intended usage), the configuration set is a sequence (list or tuple) of pre_conf_object Python objects, or a dictionary of the form {name : pre_conf_object}.

The file argument is the name of the file that a configuration was read from, and should be set to None/NULL if not used.

The following examples are written in Python. As they do not map any devices in phys_mem, they will not work as stand-alone simulations.

Example when set is a sequence:

    clock = pre_conf_object('timer', 'clock')
    clock.freq_mhz = 20
    space = pre_conf_object('phys_mem', 'memory-space')
    space.queue = clock

    SIM_add_configuration([clock, space], None)
  

Example when set is a dictionary:

    objects = {}
    objects['clock'] = pre_conf_object('timer', 'clock')
    objects['clock'].freq_mhz = 20
    objects['space'] = pre_conf_object('phys_mem', 'memory-space')
    objects['space'].queue = objects['clock']

    SIM_add_configuration(objects, None)
  

EXCEPTIONS
SimExc_General Thrown if Simics fails to initialize all objects.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_create_object, SIM_set_configuration, SIM_read_configuration

SIM_class_has_attribute()

NAME
SIM_class_has_attribute — check if class implements attribute
SYNOPSIS
bool
SIM_class_has_attribute(conf_class_t *NOTNULL cls, const char *NOTNULL attr);

DESCRIPTION
Returns true if the class cls implements an attribute with the name attr.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_attribute, SIM_get_attribute

SIM_create_object()

NAME
SIM_create_object — create and initialize object
SYNOPSIS
conf_object_t *
SIM_create_object(conf_class_t *NOTNULL cls, const char *name,
                  attr_value_t attrs);

DESCRIPTION
Creates a new instance of the configuration class cls. name must consist of a letter followed by letters, digits or underscores (_). A unique name will be created if name is an empty string or NULL. For backward compatibility, hyphens (-) are allowed instead of underscores but their use is deprecated.

The new object is initialized with attributes from attrs, which must be a list of (attribute-name, value) pairs, where each pair is a two-element list. All required attributes for the class cls must be present in attrs. In Python, attrs can be omitted (if no attributes are required), it can be normal lists: [['attribute1', value1], ['attribute2', value2]] or keyword arguments: attribute1=value1, attribute2=value2.

Attributes in ports of the cls class can be initialized by prefixing the attribute name with the port name, e.g. ['p.portname.attr', value].

The argument value may be modified, but the caller is still responsible for freeing it. Neither point applies when the function is called from Python.

RETURN VALUE
The new object, or NULL on error (in which case an exception is raised).
EXCEPTIONS
SimExc_General Thrown if the name is not well-formed, if an object named name already exists, or if the initialisation failed.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_add_configuration, SIM_set_configuration

SIM_current_checkpoint_dir()

NAME
SIM_current_checkpoint_dir — directory of checkpoint being loaded
SYNOPSIS
char *
SIM_current_checkpoint_dir(void);

DESCRIPTION
If called during the loading of a checkpoint, this function returns the checkpoint (bundle) directory. Otherwise, the return value is NULL. The directory can be absolute or relative, and may be the empty string if the checkpoint directory is the current working directory.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_read_configuration, SIM_add_configuration

SIM_delete_objects()

NAME
SIM_delete_objects, SIM_delete_object — delete a list of objects
SYNOPSIS
int
SIM_delete_objects(attr_value_t val);

int
SIM_delete_object(conf_object_t *NOTNULL obj);

DESCRIPTION
Delete the list of objects val (or the single object obj) passed as argument, provided that no reference to these objects is left in the rest of the configuration. Descendant objects of an object being deleted will also be deleted.

Some specific objects in Simics, such as sim, are protected against deletion and will be ignored by this function.

If Simics finds references to the objects in the rest of the configuration, a warning will be printed and the operation will be aborted. Note that in this case, the deletion process has started and the objects may already have began their clean-up routines. The safest action at this point is to fix the dangling references and to try to delete the objects once again.

Events posted by the objects in cycle queues or step queues will be automatically removed. Hap callbacks and script branches waiting on deleted objects will be interrupted as well.

RECURSION
While removing the listed objects, SIM_delete_objects will call various callbacks (Core_Conf_Object_Pre_Delete and Core_Conf_Object_Delete haps, as well as pre_delete_instance and delete_instance for each object). Recursive calls to SIM_delete_objects are allowed during the pre-delete phase (Pre_Delete hap and pre_delete_instance callback), and the new objects will be added to the current list of objects to delete. Recursive calls after this stage will fail.

This limited recursion is meant to let objects that "own" other objects destroy them automatically if they themselves are to be deleted. This is used for example by the standard Simics components.

BUGS
Note that for successful deletion of objects, each class should implement the proper deletion methods called by SIM_delete_objects. If the methods are not present, SIM_delete_objects will simply remove any reference to the object, but this may leave memory and resources unrecoverable.
RETURN VALUE
Returns zero if successful. Throws an exception and returns non-zero otherwise.
EXCEPTIONS
SimExc_General Thrown if an error occurred or a reference to the objects is left in the rest of the configuration.

EXECUTION CONTEXT
Global Context
EXAMPLE
The following line at the Simics prompt:
   @SIM_delete_objects(list(SIM_object_iterator(None)))
   

will delete all unprotected objects in the configuration, leaving the Simics session empty.

SIM_get_all_classes()

NAME
SIM_get_all_classes — get list of all loaded classes
SYNOPSIS
attr_value_t
SIM_get_all_classes(void);

DESCRIPTION
Return an unordered list of the names of all configuration classes loaded into simulation.

The Python function cli.global_cmds.list_classes can be used to get class names, by default including not-loaded classes.

RETURN VALUE
List of class names.
EXECUTION CONTEXT
Cell Context

SIM_get_all_objects()

NAME
SIM_get_all_objects — get list of all objects
SYNOPSIS
attr_value_t
SIM_get_all_objects(void);

DESCRIPTION
The function is going to be deprecated. Please use SIM_object_iterator instead.

Return a list of all configuration objects. The order is unspecified and may vary between calls to this function.

RETURN VALUE
List of objects.
SEE ALSO
SIM_object_iterator
EXECUTION CONTEXT
Cell Context

SIM_get_attribute()

NAME
SIM_get_attribute, SIM_get_attribute_idx — get attribute
SYNOPSIS
attr_value_t
SIM_get_attribute(conf_object_t *NOTNULL obj, const char *NOTNULL name);

attr_value_t
SIM_get_attribute_idx(conf_object_t *NOTNULL obj, const char *NOTNULL name,
                      attr_value_t *NOTNULL index);

DESCRIPTION
Extracts the attribute specified by name parameter from obj. If an error occurs, an invalid value is returned. The _idx version of the function can be used to get a single entry in a list or data attribute. The attribute must support indexing for this to work.

The caller is as usual responsible for freeing the returned value by calling SIM_attr_free.

RETURN VALUE
Attribute value. An attribute of Invalid type is returned if the attribute could not be read.
EXCEPTIONS
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_attr_free, SIM_set_attribute, SIM_attribute_error

SIM_get_attribute_attributes()

NAME
SIM_get_attribute_attributes — get attribute flags
SYNOPSIS
attr_attr_t
SIM_get_attribute_attributes(conf_class_t *NOTNULL cls,
                             const char *NOTNULL attr);

DESCRIPTION
Returns the attribute flags of the attr attribute of the class cls.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_register_attribute

SIM_get_class_attribute()

NAME
SIM_get_class_attribute, SIM_get_class_attribute_idx — get class attribute
SYNOPSIS
attr_value_t
SIM_get_class_attribute(conf_class_t *NOTNULL cls, const char *NOTNULL name);

attr_value_t
SIM_get_class_attribute_idx(conf_class_t *NOTNULL cls,
                            const char *NOTNULL name,
                            attr_value_t *NOTNULL index);

DESCRIPTION
Extracts the class attribute specified by name from the class cls. If an error occurs, an invalid value is returned. The _idx version of the function can be used to get a single entry in a list or data attribute. The attribute must support indexing for this to work.

The caller is as usual responsible for freeing the returned value by calling SIM_attr_free.

RETURN VALUE
Attribute value. A value of Invalid type is returned if the attribute could not be read.
EXCEPTIONS
EXECUTION CONTEXT
Global Context, unless the attribute documentation says otherwise.
SEE ALSO
SIM_attr_free, SIM_set_class_attribute

SIM_get_object()

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

DESCRIPTION
Returns the object with name name.

The function does an object look-up in the order; object ID, object name, and hierarchical location for all objects in the simulation. The function returns the first match from the look-up or NULL if there was no object match.

The object ID is a unique name that never changes and is returned by the SIM_object_id function. The object name is the name of the object, used for instance when printing log messages and is returned by the SIM_object_name function. The hierarchical location is the absolute location of the object in the component hierarchy. The object name and the hierarchical location is the same.

Please note that in Python Simics objects are available directly as attributes of the conf module. For example, one can access the sim object like this:

conf.sim

.

RETURN VALUE
Object, or NULL if not found.
EXCEPTIONS
SimExc_General Thrown if the object can not be found.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_object_name, SIM_object_id

SIM_get_python_interface_type()

NAME
SIM_get_python_interface_type — get Python interface type
SYNOPSIS
PyObject *
SIM_get_python_interface_type(const char *NOTNULL name);

DESCRIPTION
Returns the Python data type for the name interface, or NULL if not available from Python.

If necessary, will try to load modules registering the Python translation for this interface.

SIM_object_class()

NAME
SIM_object_class — get object class
SYNOPSIS
FORCE_INLINE conf_class_t *
SIM_object_class(const conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the class of an object.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_get_class

SIM_object_descendant()

NAME
SIM_object_descendant — return a descendant of the specified object
SYNOPSIS
conf_object_t *
SIM_object_descendant(conf_object_t *obj, const char *NOTNULL relname);

DESCRIPTION
This function returns the descendant object of obj which has the relative name relname, or NULL if no such object exists.

It is legal for the relative name to contain multiple components, like "device.p.RESET".

If obj is NULL, then the object lookup is performed relative the object hierarchy root.

If obj is instantiated at the same time as the descendant, then the function is guaranteed to succeed if called after the alloc_object phase of object initialization; i.e., it is safe for obj to invoke the function from its init_object method.

RETURN VALUE
Object, or NULL if the object has no hierarchical descendant with the specified relative name.
SEE ALSO
SIM_object_parent SIM_register_port
EXECUTION CONTEXT
Cell Context

SIM_object_is_processor()

NAME
SIM_object_is_processor — test if object is a processor
SYNOPSIS
bool
SIM_object_is_processor(conf_object_t *NOTNULL obj);

DESCRIPTION
Returns non-zero if obj is a processor.
EXECUTION CONTEXT
All contexts (including Threaded Context)

SIM_object_iterator()

NAME
SIM_object_iterator — start object iteration
SYNOPSIS
object_iter_t
SIM_object_iterator(conf_object_t *obj);

DESCRIPTION
The SIM_object_iterator function returns an iterator for the descendants of the object obj. If obj is NULL, then the returned iterator will iterate over all objects in the configuration.

The iterator returns objects sorted by name, with parents before children.

RETURN VALUE
Object iterator
EXAMPLE
Sample C code to find all objects implementing signal interface:
    #include <simics/util/vect.h>
    #include <simics/devs/signal.h>

    ...

    VECT(conf_object_t *) v = VNULL;
    object_iter_t it = SIM_object_iterator(NULL);
    conf_object_t *obj;
    while ((obj = SIM_object_iterator_next(&it)) != NULL) {
        if (SIM_C_GET_INTERFACE(obj, signal) != NULL)
            VADD(v, obj);
    }
    ...  // any code using 'v' vector here
    VFREE(v);
   

Sample Python code to find all objects implementing signal interface:

    v = []
    for obj in SIM_object_iterator(None):
        if hasattr(obj.iface, simics.SIGNAL_INTERFACE):
            v.append(obj)

The simics.SIGNAL_INTERFACE constant from the above example holds

"signal"

string. Such constants are available for some interfaces. One can safely use string literals instead.

SEE ALSO
SIM_object_iterator_next, SIM_shallow_object_iterator
EXECUTION CONTEXT
Cell Context

SIM_object_iterator_next()

NAME
SIM_object_iterator_next — get next object
SYNOPSIS
conf_object_t *
SIM_object_iterator_next(object_iter_t *iter);

DESCRIPTION
The SIM_object_iterator_next function returns the next object from an iterator obtained from SIM_object_iterator or SIM_shallow_object_iterator. If there are no more objects in the sequence, then NULL is returned.

It is illegal to call SIM_object_iterator_next using an iterator which has reached the end of its sequence.

RETURN VALUE
Next object or NULL
SEE ALSO
SIM_object_iterator_next, SIM_object_iterator
EXECUTION CONTEXT
Cell Context

SIM_object_parent()

NAME
SIM_object_parent — get object parent
SYNOPSIS
conf_object_t *
SIM_object_parent(conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the hierarchical parent of the specified object.
RETURN VALUE
Object, or NULL if the object has no hierarchical parent.
SEE ALSO
SIM_object_descendant, SIM_port_object_parent
EXECUTION CONTEXT
Cell Context

SIM_port_object_parent()

NAME
SIM_port_object_parent — get object parent
SYNOPSIS
conf_object_t *
SIM_port_object_parent(conf_object_t *NOTNULL obj);

DESCRIPTION
Returns the parent of the specified port object.
RETURN VALUE
Object, or NULL if the object is not a port object.
SEE ALSO
SIM_object_parent, SIM_object_descendant
EXECUTION CONTEXT
Cell Context

SIM_read_configuration()

NAME
SIM_read_configuration — read configuration
SYNOPSIS
void
SIM_read_configuration(const char *NOTNULL file);

DESCRIPTION
Read configuration from filename and create a machine accordingly.
EXCEPTIONS
SimExc_General Thrown if the file could not be opened, the machine was already initialized, or if an error in the configuration file was detected.

EXECUTION CONTEXT
Global Context

SIM_register_context_handler()

NAME
SIM_register_context_handler — register mandatory interface and attribute for context handler objects
SYNOPSIS
int
SIM_register_context_handler(conf_class_t *NOTNULL cls,
                             const context_handler_interface_t *NOTNULL iface);

DESCRIPTION
Register the cls class as a class for context handler objects. This includes registering the context_handler interface (iface), in addition to which SIM_register_context_handler registers a current_context attribute which will hold the current context.

The context_handler interface will be wrapped by standard functions so that standard context change behavior is taken care off automatically. This includes, among other things, making sure that the context is valid, and triggering the correct haps on context changes. Thus the context_handler implementation need only care about the effect of the change on the context_handler object itself (virtual breakpoints present in the context, cache flushing, etc.).

The return value is 0 if everything works, and non-zero if something fails. SIM_register_context_handler 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 context_handler interface has already been registered for this class.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_register_interface

SIM_set_attribute()

NAME
SIM_set_attribute, SIM_set_attribute_idx — set attribute
SYNOPSIS
set_error_t
SIM_set_attribute(conf_object_t *NOTNULL obj,
                  const char *NOTNULL name,
                  attr_value_t *NOTNULL value);

set_error_t
SIM_set_attribute_idx(conf_object_t *NOTNULL obj,
                      const char *NOTNULL name,
                      attr_value_t *NOTNULL index,
                      attr_value_t *NOTNULL value);

DESCRIPTION
Set the name attribute in obj to value.

The _idx version of the function can be used to get a single entry in a list or data attribute. For this to work, the attribute must support indexing.

After the call the value is still owned by the caller.

If the attribute setter function calls SIM_attribute_error or SIM_c_attribute_error and returns Sim_Set_Ok, it is treated like Sim_Set_IllegalValue.

RETURN VALUE
The return value is from the set_error_t enum, with Sim_Set_Ok indicating success.
EXCEPTIONS
EXECUTION CONTEXT
Global Context in general; individual attributes may be less constrained.
SEE ALSO
SIM_get_attribute, SIM_attribute_error, set_error_t

SIM_set_class_attribute()

NAME
SIM_set_class_attribute, SIM_set_class_attribute_idx — set class attribute
SYNOPSIS
set_error_t
SIM_set_class_attribute(conf_class_t *NOTNULL cls,
                        const char *NOTNULL name,
                        attr_value_t *NOTNULL value);

set_error_t
SIM_set_class_attribute_idx(conf_class_t *NOTNULL cls,
                            const char *NOTNULL name,
                            attr_value_t *NOTNULL index,
                            attr_value_t *NOTNULL value);

DESCRIPTION
Set the name attribute in cls to value.

The _idx version of the function can be used to set a single entry in a list or data attribute. For this to work, the attribute must support indexing.

After the call the value is still owned by the caller.

RETURN VALUE
The return value is from the set_error_t enum, with Sim_Set_Ok indicating success.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_get_attribute, set_error_t

SIM_set_configuration()

NAME
SIM_set_configuration — set configuration from data
SYNOPSIS
void
SIM_set_configuration(attr_value_t conf);

DESCRIPTION
Note: It is recommended that the SIM_add_configuration function is used instead of SIM_set_configuration.
This function is an alternative to reading the configuration from a file. A configuration is an attr_value_t which should have the following structure.

  (("name", "class",  ("attr_name", attr_val) ... ), ... )
  

That is a list of object specifiers containing name, class, and a list of attribute specifiers. An attribute specifier is a list of length 2 containing the attribute name and its value. SIM_set_configuration allows an easy way of parameterizing the configuration, especially if called from Python.

The argument value may be modified, but the caller is still responsible for freeing it. Neither point applies when the function is called from Python.

EXAMPLE
The following is a Python example:

  from configuration import OBJ
  from simics import SIM_set_configuration

  SIM_set_configuration([
   ["cpu0", "x86",
    ["queue", OBJ("cpu0")],
    ["freq_mhz", 20],
    ["physical_memory", OBJ("phys_mem0")]],

   ["phys_mem0", "memory-space",
    ["map",  [[0xa0000,    OBJ("vga0"),    1, 0, 0x20000],
              [0x00000,    OBJ("mem0"),    0, 0x00000, 0xA0000],
              [0xc0000,    OBJ("mem0"),    0, 0xc0000, 0x8000],
              [0xc8000,    OBJ("setmem0"), 0, 0, 0x28000],
              [0xf0000,    OBJ("mem0"),    0, 0xf0000, 0x10000],
              [0x100000,   OBJ("mem0"),    0, 0x100000, 0x3ff00000],
              [0xfee00000, OBJ("apic0"),   0, 0, 0x4000]]]],
      ... ])
  

EXCEPTIONS
SimExc_Attribute Thrown if malformed configuration list.

SimExc_General Thrown if Simics fails to initialize all objects.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_add_configuration, SIM_create_object

SIM_shallow_object_iterator()

NAME
SIM_shallow_object_iterator — start object iteration
SYNOPSIS
object_iter_t
SIM_shallow_object_iterator(conf_object_t *obj);

DESCRIPTION
The SIM_shallow_object_iterator function returns an iterator for the direct children of the object obj. If obj is NULL, then the returned iterator will iterate over objects on the root level.

The iterator returns objects sorted by name.

RETURN VALUE
Object iterator
SEE ALSO
SIM_object_iterator_next, SIM_object_iterator
EXECUTION CONTEXT
Cell Context

SIM_write_configuration_to_file()

NAME
SIM_write_configuration_to_file — write configuration
SYNOPSIS
void
SIM_write_configuration_to_file(const char *NOTNULL file, save_flags_t flags);

DESCRIPTION
Saves all objects to filename. Objects whose class_kind_t is equal to Sim_Class_Kind_Session or Sim_Class_Kind_Pseudo are not saved. This also holds for attributes (in all objects) of types Sim_Attr_Session and Sim_Attr_Pseudo.

The flags argument should be 0.

EXECUTION CONTEXT
Global Context

Embedding Simics

SIM_get_init_arg_string()

NAME
SIM_get_init_arg_string, SIM_get_init_arg_boolean — get an argument that the Simics core was initialized with
SYNOPSIS
const char *
SIM_get_init_arg_string(const char *name, const char *default_value);

bool
SIM_get_init_arg_boolean(const char *name, bool default_value);

DESCRIPTION
Returns the value of init argument name previously supplied to Simics using SIM_init_simulator2. Arguments are either strings (char *) or booleans (bool).
RETURN VALUE
The argument value or default_value if the argument was not supplied to SIM_init_simulator2 or if the argument value was NULL.
EXCEPTIONS
SimExc_General Thrown if the argument is of the wrong type.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator2

SIM_init_command_line()

NAME
SIM_init_command_line — initialize the Simics command line
SYNOPSIS
void
SIM_init_command_line(void);

DESCRIPTION
SIM_init_command_line initializes the Simics command line used when running from a Linux shell or the Windows Command Prompt.

This function must be called after SIM_init_simulator2 and should only be called when embedding Simics in another application.

EXCEPTIONS
SimExc_General Thrown if the function already has been called once.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator2, SIM_main_loop

SIM_init_environment()

NAME
SIM_init_environment — perform early initialization of the simulator
SYNOPSIS
void
SIM_init_environment(char **NOTNULL argv,
                     bool handle_signals, bool allow_core_dumps);

DESCRIPTION
The SIM_init_environment function should be called as early as possible when Simics is embedded in another application, before any other Simics API function. It will initialize Simics dynamic memory handling VTMEM, set up signal handling and perform some other early initialization.

The argv argument is a NULL terminated list of strings. It must not be NULL. It must contain at least one element, which will be used as the program name. Often you can use the argv that main receives as the value of this argument.

If handle_signals is true, Simics will install its handler for Control-C, e.g. the SIGINT signal on Linux and ConsoleCtrlHandler on Windows. Set this value to false if the embedding application handles signals itself.

If allow_core_dumps is true, Simics will not install handlers for fatal signals but instead let the application crash possibly generating a core dump on Linux systems. If the argument is false, no core dump is generated and Simics will try to catch fatal signals and return control to the command line again.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator

SIM_init_simulator2()

NAME
SIM_init_simulator2 — perform initialization of the simulator
SYNOPSIS
void
SIM_init_simulator2(init_arg_t *NOTNULL init_args);

DESCRIPTION
SIM_init_simulator2 initializes the simulator core and should only be called when embedding Simics in another application. It has to be called after SIM_init_environment but before using most other parts of the Simics API. The init_args argument is an array with init_arg_t structs, where the last entry has NULL in the name field.

Each entry in the init_args array contains an argument name and an associated value that is either a string or a boolean. Simics has a number of pre-defined arguments that are used to configure the simulator.

It is possible to provide additional arguments in the call to SIM_init_simulator2. Such arguments are ignored by Simics and assumed to be used-defined. Their values can be obtained using the SIM_get_init_arg_string and SIM_get_init_arg_boolean functions in the Simics API.

List of pre-defined parameters and their types:

batch-mode bool See -batch-mode command line flag.
deprecation-level char * One of 0, 1 and 2. See the sim.deprecation_level attribute.
expire-time char * See -expire command line flag.
gui-mode char * One of gui, mixed and no-gui
fail-on-warnings bool See -werror command line flag.
license-file char * License file to use, overriding any preference setting.
log-enable bool Deprecated.
log-file char * See -log-file command line flag.
no-settings bool See -no-settings command line flag.
no-windows bool See -no-win command line flag.
python-verbose bool Run the Python interpreter in verbose mode.
project char * See -project command line flag.
quiet bool See -quiet command line flag.
script-trace bool Show when a Simics script is entered/exited, along with any parameters passed to it and result variables returned from it.
verbose bool See -verbose command line flag.
Internal or deprecated:
allow-license-gui bool
alt-settings-dir char *
application-mode char *
check-ifaces bool
disable-dstc bool
disable-istc bool
eclipse-params char *
package-list char *
py3k-warnings bool
sign-module bool
as-py-module bool
py-import-all bool
use-module-cache bool

EXCEPTIONS
None
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_environment, SIM_get_init_arg_string, SIM_get_init_arg_boolean.

SIM_main_loop()

NAME
SIM_main_loop — run the Simics main loop
SYNOPSIS
void
SIM_main_loop(void);

DESCRIPTION
SIM_main_loop enters the main loop of Simics and never returns. It should only be called when embedding Simics in another application that wishes to transfer full control of the simulation to Simics.

The main loop waits for work requests to be posted by notifiers, SIM_thread_safe_callback and SIM_realtime_event. If the command line has been initialized it will be active as well.

If the embedding application do not wish to transfer the control to Simics while the simulation is not advancing should use the SIM_process_work or SIM_process_pending_work to make sure that Simics can process any pending idle work.

EXCEPTIONS
SimExc_General Thrown if the function is called recursively.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator2, SIM_init_command_line, SIM_realtime_event, SIM_thread_safe_callback, SIM_process_work

SIM_process_work()

NAME
SIM_process_work, SIM_process_pending_work — run the Simics main loop
SYNOPSIS
int
SIM_process_work(int (*done)(lang_void *done_data), lang_void *done_data);

int
SIM_process_pending_work(void);

DESCRIPTION
SIM_process_work and SIM_process_pending_work processes work posted by SIM_thread_safe_callback and SIM_realtime_event. These process work functions are typically called when embedding Simics in another application to allow periodic and asynchronous Simics work to run while the simulation is not advancing.

SIM_process_pending_work runs all work that has been queued up since the last call and returns immediately after.

SIM_process_work is similar but waits for new work to arrive. Each time some work has been processed, the supplied done callback is called with done_data as its only argument. A return value of 1 tells SIM_process_work to stop processing work and return control to the caller again while 0 tells it to continue.

The done predicate is only evaluated between callbacks that are run in Global Context, that is, not registered with the run_in_thread parameter set).

The process work functions return -1 if the user has pressed the interrupt key before or while they were running, provided that the simulator core was initialized to catch signals. Otherwise the return value is 0.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator2, SIM_main_loop, SIM_realtime_event, SIM_thread_safe_callback

SIM_set_frontend_context()

NAME
SIM_set_frontend_context — register a stack context buffer for Simics to longjmp back to
SYNOPSIS
void
SIM_set_frontend_context(void *context);

DESCRIPTION
When Simics encounters a fatal error that it cannot handle, it uses longjmp() to give control back to the main loop. The longjmp destination depends on the stack context buffer registered by the embedding application using SIM_set_frontend_context.

If the embedding application uses Simics's own main loop to control the simulation, i.e., by running SIM_main_loop, then there is no need to register any stack context buffer.

A stack context buffer is created by calling sigsetjmp() on Linux and setjmp() on Windows.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_init_simulator2, SIM_main_loop, SIM_process_work

Haps

SIM_get_all_hap_types()

NAME
SIM_get_all_hap_types — get list of all hap types
SYNOPSIS
attr_value_t
SIM_get_all_hap_types(void);

DESCRIPTION
Get a list of the names of all registered hap types.
RETURN VALUE
Attribute list of strings.
EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_hap_get_number, SIM_hap_add_type

SIM_hap_add_callback()

NAME
SIM_hap_add_callback, SIM_hap_add_callback_index, SIM_hap_add_callback_range, SIM_hap_add_callback_obj, SIM_hap_add_callback_obj_index, SIM_hap_add_callback_obj_range — install callback on a hap
SYNOPSIS
hap_handle_t
SIM_hap_add_callback(const char *NOTNULL hap,
                     NOTNULL obj_hap_func_t func,
                     lang_void *user_data);

hap_handle_t
SIM_hap_add_callback_index(const char *NOTNULL hap,
                           NOTNULL obj_hap_func_t func,
                           lang_void *user_data,
                           int64 index);

hap_handle_t
SIM_hap_add_callback_range(const char *NOTNULL hap,
                           NOTNULL obj_hap_func_t func,
                           lang_void *user_data,
                           int64 start,
                           int64 end);

hap_handle_t
SIM_hap_add_callback_obj(const char *NOTNULL hap,
                         conf_object_t *NOTNULL obj,
                         hap_flags_t flags,
                         NOTNULL obj_hap_func_t func,
                         lang_void *user_data);

hap_handle_t
SIM_hap_add_callback_obj_index(const char *NOTNULL hap,
                               conf_object_t *NOTNULL obj,
                               hap_flags_t flags,
                               NOTNULL obj_hap_func_t func,
                               lang_void *user_data,
                               int64 index);

hap_handle_t
SIM_hap_add_callback_obj_range(const char *NOTNULL hap,
                               conf_object_t *NOTNULL obj,
                               hap_flags_t flags,
                               NOTNULL obj_hap_func_t func,
                               lang_void *user_data,
                               int64 start,
                               int64 end);

DESCRIPTION
Registers a function, pointed to by func, to be called when hap occurs for object obj. If a hap add function that does not have the obj argument is used, then the callback function will be called regardless of what object that triggers the hap. The user_data argument is the callback-specific data, and it will be passed as first argument to the installed callback function.

Some hap add functions also take a flags argument. This flag is currently Simics internal and should be set to 0.

The hap callback functions should not return any data. In C, the functions are declared to have a void return type and in Python, any return value is ignored. Since callback functions with different arguments may be installed using the same API function, the compiler may warn about a type mismatch. The solution is to cast the callback function pointer to the obj_hap_func_t type.

The callback will be called in Cell Context, unless the documentation for the hap states otherwise.

In hap functions, the execution can be interrupted by calling SIM_break_simulation. If a frontend or Python exception is raised, an error message will be printed including a stack trace if the callback is written in Python.

The _index_ and _range_ versions will install callbacks that only trigger for a specified index, or range of indices. The index is specific for each hap type, see the hap documentation. The index and range must be non-negative and the end of the range must not be lower than the start.

typedef int hap_handle_t;

RETURN VALUE
The return value is a hap callback handle (identifier) of the type hap_handle_t, or -1 on error. This handle can be used to remove the installed callback with SIM_hap_delete_callback_id.
EXCEPTIONS
SimExc_Lookup Thrown if the hap does not exist.

SimExc_Attribute Thrown if the index is negative or if the range is negative in value or size.

EXECUTION CONTEXT
Cell Context for hap callbacks tied to an object, and Global Context for hap callbacks not tied to an object. An exception is made for callbacks on Core_Breakpoint_Memop, which can be installed with SIM_hap_add_callback_index even in Cell Context.

SIM_hap_delete_callback()

NAME
SIM_hap_delete_callback, SIM_hap_delete_callback_obj, SIM_hap_delete_callback_id, SIM_hap_delete_callback_obj_id — delete installed hap callback
SYNOPSIS
void
SIM_hap_delete_callback(const char *NOTNULL hap,
                        NOTNULL obj_hap_func_t func, lang_void *user_data);

void
SIM_hap_delete_callback_obj(const char *NOTNULL hap,
                            conf_object_t *NOTNULL obj,
                            NOTNULL obj_hap_func_t func, lang_void *user_data);

void
SIM_hap_delete_callback_id(const char *NOTNULL hap, hap_handle_t handle);

void
SIM_hap_delete_callback_obj_id(const char *NOTNULL hap,
                               conf_object_t *NOTNULL obj, hap_handle_t handle);

DESCRIPTION
Removes a callback for a hap type specified by the hap argument.

The SIM_hap_delete_callback_obj... functions will remove a callback that is installed on the specified object obj.

SIM_hap_delete_callback removes a callback not associated with any object, with the callback function func and the same user_data. The SIM_hap_delete_callback_..._id functions take a hap handle argument instead, as returned by the SIM_hap_add_callback... functions.

These functions will trigger the Core_Hap_Callback_Removed hap for each removed callback.

EXCEPTIONS
SimExc_Lookup Thrown if the specified hap does not exist.
EXECUTION CONTEXT
Cell Context for callbacks tied to an object. Global Context for callbacks not tied to an object.

Logging

SIM_get_quiet()

NAME
SIM_get_quiet — return setting of the quiet flag
SYNOPSIS
bool
SIM_get_quiet(void);

DESCRIPTION
This function returns the current value of Simics's quiet flag.
EXECUTION CONTEXT
Cell Context

SIM_get_verbose()

NAME
SIM_get_verbose — get the verbose flag
SYNOPSIS
bool
SIM_get_verbose(void);

DESCRIPTION
This function returns the value of Simics's verbosity flag (corresponding to the -verbose command line argument).
EXECUTION CONTEXT
Cell Context

SIM_set_quiet()

NAME
SIM_set_quiet — enable/disable quiet mode
SYNOPSIS
void
SIM_set_quiet(bool quiet);

DESCRIPTION
Calling this function with an argument of true will enable the quiet mode, whereas an argument of false will disable it. Any other arguments will cause a frontend exception. Please note that enabling the quiet mode will disable verbose mode.
EXECUTION CONTEXT
Cell Context

SIM_set_verbose()

NAME
SIM_set_verbose — enable/disable verbose mode
SYNOPSIS
void
SIM_set_verbose(bool verbose);

DESCRIPTION
This function sets Simics's internal verbosity flag (corresponding to the -verbose command line argument). The verbose argument can be either true or false. Note that setting this flag will disable quiet mode.
EXECUTION CONTEXT
Cell Context

Memory

SIM_load_binary()

NAME
SIM_load_binary — read an executable file into memory
SYNOPSIS
physical_address_t
SIM_load_binary(conf_object_t *NOTNULL obj, const char *NOTNULL file,
                physical_address_t offset, bool use_pa, bool verbose);

DESCRIPTION
Read a binary file (ELF, Motorola S-Record, PE32, PE32+, or TI COFF format) into memory and return the code entry point.

The file will be loaded at the address formed by adding the virtual load address from the file, with the offset offset. If the flag use_pa is set, the ELF physical load address is used instead. The verbose flag will cause Simics to print info about the binary to the console.

The memory space to load into is given in the obj parameter. If the given space is a CPU object, its current virtual address space will be used, and addresses will be translated before writing to the physical memory space attached to the CPU.

If the file is not found in the current directory, the search path (see add-directory) is used to find the file.

EXCEPTIONS
SimExc_IOError Thrown if there was a problem reading the file.
SimExc_General Thrown if binary cannot be read into memory.
RETURN VALUE
The code entry address.
EXECUTION CONTEXT
Global Context

SIM_load_file()

NAME
SIM_load_file — read a file into memory
SYNOPSIS
void
SIM_load_file(conf_object_t *NOTNULL obj, const char *NOTNULL file,
              physical_address_t base_address, bool verbose);

DESCRIPTION
Loads the contents of file into memory starting at address base_address. The obj argument can either be a processor, a memory-space, or an image object. In case of a processor, the address is interpreted as a virtual address.

The file can be either a raw binary file or a file in the craff format.

The verbose flag will cause Simics to print some information about the load.

EXCEPTIONS
SimExc_IOError Thrown if there was a problem reading the file.
SimExc_General Thrown if file cannot be read into memory.
EXECUTION CONTEXT
Cell Context

SIM_read_byte()

NAME
SIM_read_byte, SIM_write_byte — read/write byte from a memory space
SYNOPSIS
uint8
SIM_read_byte(conf_object_t *NOTNULL obj, generic_address_t paddr);

void
SIM_write_byte(conf_object_t *NOTNULL obj,
               generic_address_t paddr, uint8 value);

DESCRIPTION
Read or write a byte from a given address in the memory space obj.
EXCEPTIONS
SimExc_Memory Thrown if the memory space threw an exception

SimExc_General Thrown if the object does not implement the memory space interface.

RETURN VALUE
The byte read.
EXECUTION CONTEXT
Cell Context

SIM_read_phys_memory()

NAME
SIM_read_phys_memory — read data from a physical address
SYNOPSIS
uint64
SIM_read_phys_memory(conf_object_t *NOTNULL cpu,
                     physical_address_t paddr,
                     int length);

DESCRIPTION
Reads length bytes from address paddr in the physical memory space associated with the processor cpu.

Up to 8 bytes can be read in one call. The memory access will be of inquiry type, i.e. no timing-model or snoop device will be called.

For non-inquiry accesses, use the memory_space interface directly.

EXCEPTIONS
SimExc_Memory Thrown if no memory defined at paddr.

SimExc_Attribute Thrown if length is out of range.

SimExc_General Thrown if the processors physical memory does not implement the necessary interface methods.

RETURN VALUE
The read data, zero-extended.
EXECUTION CONTEXT
Cell Context

SIM_read_phys_memory_tags()

NAME
SIM_read_phys_memory_tags, SIM_write_phys_memory_tags — access auxiliary bits in physical memory
SYNOPSIS
uint64
SIM_read_phys_memory_tags(conf_object_t *NOTNULL mem_space,
                          physical_address_t paddr, unsigned ntags);

void
SIM_write_phys_memory_tags(conf_object_t *NOTNULL mem_space,
                           physical_address_t paddr,
                           uint64 tag_bits, unsigned ntags);

DESCRIPTION
Reads or writes ntags auxiliary bits starting at paddr in the physical memory space mem_space. Up to 64 bits can be accessed at once. The bits are specified and returned right-aligned, least significant bit corresponding to the lowest address.
EXECUTION CONTEXT
Cell Context

SIM_write_phys_memory()

NAME
SIM_write_phys_memory — write data to a physical address
SYNOPSIS
void
SIM_write_phys_memory(conf_object_t *NOTNULL cpu,
                      physical_address_t paddr,
                      uint64 value, int length);

DESCRIPTION
Writes length bytes to address paddr in the physical memory space associated with the processor cpu.

Up to 8 bytes can be written in one call. The memory access will be of inquiry type, i.e. no timing-model or snoop device will be called.

EXCEPTIONS
SimExc_Memory Thrown if no memory defined at paddr.

SimExc_Attribute Thrown if length is out of range.

SimExc_General Thrown if the processors physical memory does not implement the necessary interface methods.

EXECUTION CONTEXT
Cell Context

Modules

SIM_add_module_dir()

NAME
SIM_add_module_dir — add loadable module search path
SYNOPSIS
void
SIM_add_module_dir(const char *path);

DESCRIPTION
Add given path to the list of paths where Simics searches for loadable modules. The function SIM_module_list_refresh has to be called after calling this function, for the change to take effect.
EXECUTION CONTEXT
Global Context

SIM_get_all_failed_modules()

NAME
SIM_get_all_failed_modules — return a list of all modules that failed to load
SYNOPSIS
attr_value_t
SIM_get_all_failed_modules(void);

DESCRIPTION
A failed module is a module that is not loadable by the current version of Simics. The list returned contains information about why the module failed. Each list entry is another list with module specific information. The layout of this sub-list is described below. The list may change in future Simics versions.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_get_all_modules

SIM_get_all_modules()

NAME
SIM_get_all_modules — return a list of all modules
SYNOPSIS
attr_value_t
SIM_get_all_modules(void);

DESCRIPTION
The list returned contains information about all modules that can be loaded into Simics. Each list entry is another list with module specific information. The layout of this sub-list is described below. The list may grow in future Simics version, but the currently defined fields will not change.
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_get_all_failed_modules

SIM_load_module()

NAME
SIM_load_module — load a module
SYNOPSIS
void
SIM_load_module(const char *NOTNULL module);

DESCRIPTION
Load a Simics module. Normally, modules are loaded automatically as needed for the configuration classes they implement, and there is rarely any need to call this function explicitly.

The module argument is the name of the module (not file name) to be loaded.

EXCEPTIONS
SimExc_License Thrown if the module requires a non-existing license feature.

SimExc_General Thrown if the module failed to load for other reasons.

EXECUTION CONTEXT
Global Context

SIM_module_list_refresh()

NAME
SIM_module_list_refresh — refresh list of loadable modules
SYNOPSIS
void
SIM_module_list_refresh(void);

DESCRIPTION
Simics maintains a list of all modules that can be loaded successfully. If a module is changed or added, the list has to be refreshed before Simics can load this module.
EXECUTION CONTEXT
Global Context

Object Locks

SIM_ASSERT_CELL_CONTEXT()

NAME
SIM_ASSERT_CELL_CONTEXT — assert Cell Context
SYNOPSIS
SIM_ASSERT_CELL_CONTEXT(obj);

DESCRIPTION
The SIM_ASSERT_CELL_CONTEXT function verifies that cell thread domain associated with obj is held by the calling thread and raises a hard failure if this is not the case.

In other worlds, the macro ensures that the execution context is either Cell Context or Global Context.

SIM_ASSERT_OBJECT_LOCK()

NAME
SIM_ASSERT_OBJECT_LOCK — assert thread domain is held
SYNOPSIS
SIM_ASSERT_OBJECT_LOCK(obj);

DESCRIPTION
The SIM_ASSERT_OBJECT_LOCK function checks that the thread domain associated with obj is held. A hard failure is raised if the thread domain is not held.

SIM_acquire_cell()

NAME
SIM_acquire_cell, SIM_release_cell, SIM_ACQUIRE_CELL, SIM_RELEASE_CELL — enter Cell Context
SYNOPSIS
domain_lock_t *
SIM_acquire_cell(conf_object_t *NOTNULL obj,
                 const char *NOTNULL function_name,
                 const char *NOTNULL source_location);

void
SIM_release_cell(conf_object_t *NOTNULL obj, domain_lock_t *lock);

SIM_ACQUIRE_CELL(obj, lockp);

SIM_RELEASE_CELL(obj, lockp);

DESCRIPTION
Enters Cell Context for the cell associated with the object obj.

As part of entering Cell Context, the cell thread domain for the cell associated with obj is acquired.

Entering Cell Context multiple times is allowed, but acquired thread domains must be released in strict reverse order.

This function will block until the cell is available if another thread is currently holding the cell thread domain. While blocking, any previously held domains can be acquired by the thread already in Cell Context. Thus, the caller must be prepared to handle e.g. incoming interface calls.

In Cell Context, API functions marked with Cell Context or Global Context can be called safely, and interfaces on objects belonging to the same cell can be called directly. More generally, the full Standard Device Model applies in Cell Context. Refer to the chapter about threading in the API Reference Manual for more details.

The macro version of this API call sets the function_name and source_location arguments automatically with the information where the API call was made. This data is used when lock statistics collection is enabled through the enable-object-lock-stats command.

SEE ALSO
SIM_acquire_object, SIM_acquire_target
RETURN VALUE
SIM_acquire_cell returns a domain lock handle which should be passed as an argument to SIM_release_cell when the lock is released. SIM_ACQUIRE_CELL does not return anything but instead stores the domain lock handle in the pointer passed as the second argument.
EXECUTION CONTEXT
Any

SIM_acquire_object()

NAME
SIM_acquire_object, SIM_release_object, SIM_ACQUIRE_OBJECT, SIM_RELEASE_OBJECT — acquire thread domain
SYNOPSIS
domain_lock_t *
SIM_acquire_object(conf_object_t *NOTNULL obj,
                   const char *NOTNULL function_name,
                   const char *NOTNULL source_location);

void
SIM_release_object(conf_object_t *NOTNULL obj, domain_lock_t *lock);

SIM_ACQUIRE_OBJECT(obj, lockp);

SIM_RELEASE_OBJECT(obj, lockp);

DESCRIPTION
Acquires the thread domain associated with the object obj.

A particular thread domain can only be held by a single thread at a time, and this function blocks until the domain is available. Once the domain is held, the thread can safely access state protected by the domain.

While blocking, any previously held domains can be acquired by threads with higher priority, such as a thread running in Cell Context.

More than one thread domain can be held simultaneously, and the same thread domain may be acquired multiple times. However, domains must be released in strict reverse order.

This function is typically used by models using the Threaded Device Model to acquire the model's own thread domain from its interface methods. In this case, obj is set to the model itself.

The macro version of this API call sets the function_name and source_location arguments automatically with the information where the API call was made. This data is used when lock statistics collection is enabled through the enable-object-lock-stats command.

More details about thread domains and the threading model are available in the chapter about threading in the API Reference Manual.

SEE ALSO
SIM_acquire_target, SIM_acquire_cell
RETURN VALUE
SIM_acquire_object returns a domain lock handle which should be passed as an argument to SIM_release_object when the lock is released. SIM_ACQUIRE_OBJECT does not return anything but instead stores the domain lock handle in the pointer passed as the second argument.
EXECUTION CONTEXT
Any

SIM_acquire_object_for_execution()

NAME
SIM_acquire_object_for_execution — acquire object lock for execution
SYNOPSIS
domain_lock_t *
SIM_acquire_object_for_execution(conf_object_t *NOTNULL obj);

DESCRIPTION
Acquire the thread domain lock associated with object arg.

Note: This API function is considered tech-preview and may change without notice.

RETURN VALUE
Domain lock handle which should be passed as an argument to SIM_release_object when the lock is released.
EXECUTION CONTEXT
Any

SIM_acquire_target()

NAME
SIM_acquire_target, SIM_release_target, SIM_ACQUIRE_TARGET, SIM_RELEASE_TARGET — conditionally enter Cell Context
SYNOPSIS
domain_lock_t *
SIM_acquire_target(conf_object_t *NOTNULL obj,
                   const char *NOTNULL function_name,
                   const char *NOTNULL source_location);

void
SIM_release_target(conf_object_t *NOTNULL obj, domain_lock_t *lock);

SIM_ACQUIRE_TARGET(obj, lockp);

SIM_RELEASE_TARGET(obj, lockp);

DESCRIPTION
Enters Cell Context if the specified object obj uses the Standard Device Model. The function does nothing if obj is a thread-aware object, i.e., if the object belongs to a thread-domain other than the cell.

The intended use for this function is ensuring that Cell Context is entered before a code running in Threaded Context invokes an interface on some external object. If the external object is thread aware, and does not require Cell Context, this function avoids entering Cell Context as an optimization.

The macro version of this API call sets the function_name and source_location arguments automatically with the information where the API call was made. This data is used when lock statistics collection is enabled through the enable-object-lock-stats command.

RETURN VALUE
SIM_acquire_target returns a domain lock handle which should be passed as an argument to SIM_release_target when the lock is released. SIM_ACQUIRE_TARGET does not return anything but instead stores the domain lock handle in the pointer passed as the second argument.
SEE ALSO
SIM_acquire_object, SIM_acquire_cell
EXECUTION CONTEXT
Any

SIM_drop_thread_domains()

NAME
SIM_drop_thread_domains, SIM_reacquire_thread_domains, SIM_DROP_THREAD_DOMAINS, SIM_REACQUIRE_THREAD_DOMAINS — temporarily release all held thread domains
SYNOPSIS
domain_lock_t *
SIM_drop_thread_domains(void);

void
SIM_reacquire_thread_domains(domain_lock_t *dl);

SIM_DROP_THREAD_DOMAINS(obj, lockp);

SIM_REACQUIRE_THREAD_DOMAINS(obj, lockp);

DESCRIPTION
Temporarily releases all held thread domains and enters Threaded Context.

This function is intended to use before blocking is initiated on an external synchronization mechanism, like a condition variable. Releasing thread domains before blocking is often necessary to avoid deadlock situations where other threads get stuck trying to acquire thread domains held by the blocking thread.

Each call to SIM_drop_thread_domains must be followed with a call to SIM_reacquire_thread_domains to reacquire the released thread domains. This must be done from the same thread.

If the purpose of the call is just to provide other threads an opportunity to acquire held domains, then the more efficient SIM_yield_thread_domains should be used instead.

The macro versions of the API calls are currently wrappers of the corresponding SIM-function. In the future, they might collect extra information about where in the code the domain locks are reacquired.

RETURN VALUE
SIM_drop_thread_domains returns a domain lock handle which should be passed as an argument to SIM_reacquire_thread_domains_object. The SIM_DROP_THREAD_DOMAINS does not return anything but instead stores the domain lock handle in the pointer passed as the second argument.
SEE ALSO
SIM_yield_thread_domains
EXECUTION CONTEXT
Any

SIM_yield_thread_domains()

NAME
SIM_yield_thread_domains — yield held thread domains
SYNOPSIS
void
SIM_yield_thread_domains(void);

DESCRIPTION
Yields held thread domains if there are other threads waiting to acquire them.

The function blocks until all threads waiting for one of the held domains have had the opportunity to acquire the domain in question, and then resumes execution with the domains held again.

One example usage of this function is when a CPU model is notified through the execute_control interface that another thread wants to acquire the CPU's thread domain. Then the CPU function should call this function as quickly as possible, preferably before starting the simulation of the next instruction.

SEE ALSO
SIM_drop_thread_domains, SIM_acquire_object
EXECUTION CONTEXT
Any

Output

SIM_add_output_handler()

NAME
SIM_add_output_handler, SIM_remove_output_handler — add or remove output handler
SYNOPSIS
void
SIM_add_output_handler(void (*NOTNULL f)(lang_void *user_data,
                                         const char *text,
                                         size_t length),
                       lang_void *user_data);

void
SIM_remove_output_handler(void (*NOTNULL f)(lang_void *user_data,
                                            const char *text,
                                            size_t length),
                          lang_void *user_data);

DESCRIPTION
SIM_add_output_handler registers f(user_data, text, length) to be called whenever there is text output from Simics.

text contains length bytes of output data. user_data is passed unchanged to the output handler.

SIM_remove_output_handler removes f as an output recipient. If user_data is NULL, all output handlers with the same function will be removed; otherwise, only those with equal user_data will be removed.

Output handlers must be thread-safe in order to handle output from different threads properly. There will only be one activation of each handler at a given instant so strict re-entrancy is not required, but proper locking around resources shared with other code should be in place.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_write

SIM_write()

NAME
SIM_write, SIM_flush, SIM_putchar, SIM_puts, SIM_printf_vararg, SIM_printf — text output routines
SYNOPSIS
int
SIM_write(const void *NOTNULL src, int length);

int
SIM_flush(void);

int
SIM_putchar(int c);

int
SIM_puts(const char *NOTNULL s);

int
SIM_printf_vararg(const char *NOTNULL format, va_list ap);

int
SIM_printf(const char *NOTNULL format, ...);

DESCRIPTION
These are the Simics versions of the write, putchar, puts, printf, vprintf, and fflush C library functions. The arguments and return values are the same as for the library functions, except for SIM_write which does not take any file argument.

The output will be sent to stdout, but more output recipients can be added using the SIM_add_output_handler function. Output is line buffered. SIM_flush will force output of an unterminated line.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_add_output_handler

Path

SIM_add_directory()

NAME
SIM_add_directory — add directory to search path
SYNOPSIS
void
SIM_add_directory(const char *NOTNULL directory, bool prepend);

DESCRIPTION
Adds a directory to Simics's search path. This is a list of directories which Simics uses when searching for files such as disk dumps, kernel images, etc.

The directory argument is first converted using SIM_native_path, to yield a path on host native form. If the path does not exist, a frontend exception is raised.

If prepend is true, the directory is inserted first in the list of directories.

This list of directories is saved as the attribute simics_path when doing write-configuration. Each directory is first converted to absolute form if relative.

EXCEPTIONS
SimExc_General Thrown if the directory does not exist.

SEE ALSO
SIM_lookup_file, SIM_clear_directories
EXECUTION CONTEXT
Global Context

SIM_clear_directories()

NAME
SIM_clear_directories — clear the search path
SYNOPSIS
void
SIM_clear_directories(void);

DESCRIPTION
Deletes all directories from the search path.
SEE ALSO
SIM_add_directory, SIM_lookup_file
EXECUTION CONTEXT
Global Context

SIM_get_directories()

NAME
SIM_get_directories — get the current search path
SYNOPSIS
attr_value_t
SIM_get_directories(void);

DESCRIPTION
Returns the current value of the directory search path.
EXECUTION CONTEXT
Cell Context

SIM_lookup_file()

NAME
SIM_lookup_file — find a file using simics search path
SYNOPSIS
char *
SIM_lookup_file(const char *file);

DESCRIPTION
Searches for a file in the Simics search path.

The returned path will always be in host native format, so it will not need to be converted. See SIM_native_path for more details on what "host native format" means.

NULL is returned if file cannot be found.

The search algorithm is as follows.

If the file was found, a pointer to the full path to the file is returned. The ownership of the string is passed to the caller.

SEE ALSO
SIM_add_directory, SIM_clear_directories
EXECUTION CONTEXT
Cell Context

SIM_native_path()

NAME
SIM_native_path — convert path to its native form
SYNOPSIS
char *
SIM_native_path(const char *NOTNULL path);

DESCRIPTION
Translates a path to its host native form. This functions is a no-op on all platforms except Windows.

The value returned by this function is allocated and owned by the caller.

EXECUTION CONTEXT
Cell Context

Processor

SIM_clear_augmentation_bit()

NAME
SIM_clear_augmentation_bit, SIM_get_augmentation_bit, SIM_set_augmentation_bit — convenience functions to work with augmented memory bits
SYNOPSIS
FORCE_INLINE void
SIM_clear_augmentation_bit(uint8 *tag_page_data, unsigned pofs);

FORCE_INLINE int
SIM_get_augmentation_bit(uint8 *tag_page_data, unsigned pofs);

FORCE_INLINE void
SIM_set_augmentation_bit(uint8 *tag_page_data, unsigned pofs);

DESCRIPTION
The SIM_clear_augmentation_bit, SIM_get_augmentation_bit, and SIM_set_augmentation_bit functions are used to modify and read augmented memory bits. The direct_memory_tags interface supports augmented memory through the data field in the direct_memory_tags_t struct.
EXECUTION CONTEXT
Cell Context

SIM_disassemble_address()

NAME
SIM_disassemble_address — disassemble address
SYNOPSIS
tuple_int_string_t
SIM_disassemble_address(conf_object_t *NOTNULL cpu, generic_address_t address, 
                        int logical, int sub_operation);

DESCRIPTION
This function disassembles the instruction at the given address. Address is either a physical address (logical == 0) or a logical address (logical == 1). For VLIW architectures, sub_operation is used to select which sub-operation to disassemble. A request for a not present sub-operation (for example sub-operation != 0 for non-VLIW architectures) results in the int part of the return tuple being set to zero.

A tuple_int_string_t is returned which contains the disassembly string as well as the length of the instruction in bytes. tuple_int_string_t is defined like this:

typedef struct {
        int integer;
        char *string;
} tuple_int_string_t;

For the Sparc and PowerPC targets the length is always 4 bytes.

This function can be more convenient to use than the disassemble function in the processor_info interface.

EXCEPTIONS
SimExc_General Thrown if arguments are invalid.

SimExc_Memory Thrown if the address is undefined or not mapped in the MMU (for logical addresses).

EXECUTION CONTEXT
Cell Context

SIM_get_all_processors()

NAME
SIM_get_all_processors — get list of all processors
SYNOPSIS
attr_value_t
SIM_get_all_processors(void);

DESCRIPTION
Return a list of all processor objects.
RETURN VALUE
List of processors.
EXECUTION CONTEXT
Cell Context

SIM_get_processor()

NAME
SIM_get_processor — get processor pointer from number
SYNOPSIS
conf_object_t *
SIM_get_processor(int proc_no);

DESCRIPTION
Converts processor id number to processor pointer. This function cannot be used until a configuration had been loaded successfully.
EXCEPTIONS
SimExc_Index Thrown if no processor with number proc_no exists.

RETURN VALUE
The processor pointer, NULL on failure.
EXECUTION CONTEXT
Cell Context

SIM_get_processor_number()

NAME
SIM_get_processor_number — get the number of a processor
SYNOPSIS
int
SIM_get_processor_number(const conf_object_t *NOTNULL cpu);

DESCRIPTION
Returns the global processor number for a processor in Simics.
RETURN VALUE
The processor number
EXECUTION CONTEXT
Cell Context

SIM_number_processors()

NAME
SIM_number_processors — number of processors
SYNOPSIS
int
SIM_number_processors(void);

DESCRIPTION
Returns the current total number of processors in the system.
RETURN VALUE
Number of processors.
EXECUTION CONTEXT
Cell Context

SIM_processor_privilege_level()

NAME
SIM_processor_privilege_level — return the current privilege level for a processor
SYNOPSIS
int
SIM_processor_privilege_level(conf_object_t *NOTNULL cpu);

DESCRIPTION
Return the current privilege level for a processor. The definition of privilege levels depends on the processor type.
RETURN VALUE
For SPARC, and PowerPC, and ARM processors: 0 for User mode, and 1 for Supervisor mode.
For x86 and IA-64 processors: 0-3, where 0 is the most privileged.
For MIPS processors: 0
EXCEPTIONS
SimExc_General Thrown if cpu does not implement the privilege level interface function.

EXECUTION CONTEXT
Cell Context

SIM_reset_processor()

NAME
SIM_reset_processor — reset the processor
SYNOPSIS
void
SIM_reset_processor(conf_object_t *NOTNULL cpu, int hard_reset);

DESCRIPTION
Performs a reset on the processor, causing a System Reset exception to be taken when execution continues. cpu is the processor that should be reset. hard_reset indicates if a soft (0) or hard (1) (power-on type) reset should be performed. If a hard reset is requested, a number of register are initiated with default values.
EXCEPTIONS
SimExc_General Thrown if cpu does not implement reset.

EXECUTION CONTEXT
Cell Context

Profiling

SIM_iter_next()

NAME
SIM_iter_next, SIM_iter_addr, SIM_iter_free — Iterate over address profile counters
SYNOPSIS
FORCE_INLINE uint64
SIM_iter_next(addr_prof_iter_t *iter);

FORCE_INLINE generic_address_t
SIM_iter_addr(addr_prof_iter_t *iter);

FORCE_INLINE void
SIM_iter_free(addr_prof_iter_t *iter);

DESCRIPTION
EXPERIMENTAL. While this functionality is expected to be retained in future releases, the interface is likely to change.

An address profile iterator visits some of the counters of an address profiler in some order. It is obtained from the iter function of the address_profiler interface.

SIM_iter_next advances the address profile iterator iter to the next nonzero counter and returns the count. It will return 0 when there are no more counters to visit. Note that the order in which the counters are visited is unspecified.

SIM_iter_addr returns the address of the counter returned by the most recent call to iter_next.

When you are done with the iterator, deallocate it with SIM_iter_free.

EXECUTION CONTEXT
Cell Context

Simulation Control

SIM_break_message()

NAME
SIM_break_message — stop the simulation
SYNOPSIS
void
SIM_break_message(const char *msg);

DESCRIPTION
Display the reason why Simics will stop simulation.

This is similar to SIM_break_simulation, with the difference that it doesn't actually break the simulation. It can be used by code that wants to display a break message and stop the simulation by some other means.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_break_simulation

SIM_break_simulation()

NAME
SIM_break_simulation — stop the simulation
SYNOPSIS
void
SIM_break_simulation(const char *msg);

DESCRIPTION
Ask Simics to stop the simulation as soon as possible, displaying the supplied message.

Simics will normally stop before the next instruction is executed. If this function is called when an instruction has started executing, and the instruction can be aborted, it will rewind to before the instruction. This might leave the simulation in a state where some repeatable part of the instruction is already executed.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_break_message

SIM_continue()

NAME
SIM_continue — run the simulation
SYNOPSIS
pc_step_t
SIM_continue(int64 steps);

DESCRIPTION
Run the simulation. In typical usage with steps being 0, the simulation will run forward until it is stopped, either by a breakpoint, internal event, or through the user interface.

With a non-zero steps, Simics will make sure that at least one processor runs steps steps and then stop the simulation. As with steps being 0, the function can also return early if other break criteria are met.

In order to properly control when simulation stops in time, it is advisable to use step or cycle breakpoints on one or more objects.

The function returns non-zero if the simulation was started, and 0 otherwise.

EXCEPTIONS
SimExc_General Thrown if the simulation could not be started. Check the exception message for more information.

EXECUTION CONTEXT
Global Context

SIM_current_clock()

NAME
SIM_current_clock — return current clock
SYNOPSIS
conf_object_t *
SIM_current_clock(void);

DESCRIPTION
Returns the clock (an object implementing the cycle interface) that is driving the simulation in the current cell and current thread. In Global Context, NULL is returned.

Normally, one uses SIM_object_clock to obtain the clock used for posting events. E.g. when a device processes a transaction it typically takes the clock from the initiator.

This function can instead be used in situations where it is important to know the currently running clock, e.g. to post events right after the current instruction finishes.

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_object_clock

SIM_simics_is_running()

NAME
SIM_simics_is_running — check if simulation is running
SYNOPSIS
bool
SIM_simics_is_running(void);

DESCRIPTION
Returns true if the simulation is running, e.g. if it has been started using SIM_continue, or false otherwise. It also returns true when the simulation is reversing.
EXECUTION CONTEXT
Cell Context

Simulation Independent Services

SIM_cancel_realtime_event()

NAME
SIM_cancel_realtime_event — cancel callback in host time
SYNOPSIS
int
SIM_cancel_realtime_event(int64 id);

DESCRIPTION
Cancel a callback registered by SIM_realtime_event, whose return value is specified as id.

Returns 0 if the callback existed and was cancelled, or -1 if no callback with that identifier existed. (No exception is raised.)

EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_realtime_event

SIM_notify_on_socket()

NAME
SIM_notify_on_socket, SIM_notify_on_object, SIM_notify_on_descriptor — register notification on host I/O events
SYNOPSIS
void
SIM_notify_on_socket(socket_t sock, notify_mode_t mode, int run_in_thread,
                     void (*callback)(lang_void *data), lang_void *data);

void
SIM_notify_on_object(HANDLE obj, int run_in_thread,
                     void (*callback)(lang_void *data), lang_void *data);

void
SIM_notify_on_descriptor(int fd, notify_mode_t mode, int run_in_thread,
                         void (*callback)(lang_void *data),
                         lang_void *data);

DESCRIPTION
These functions allow the function callback to be called with argument data whenever a specific I/O event occurs on the host machine. If callback is a null function pointer, a previously installed notification is removed.

If run_in_thread is 1, the callback function may be run in a thread where it cannot access or call anything in Simics except for these functions and SIM_thread_safe_callback. If run_in_thread is zero, the callback function is always run in Global Context. This may incur a small penalty in latency (time between the occurrence of the host event and execution of callback).

Values other than 0 and 1 for run_in_thread are reserved.

Notification on a specific event will be blocked during the execution of its callback function.

SIM_notify_on_socket will call a registered callback depending on mode:

mode condition
Sim_NM_Read Socket is readable, closed, or incoming connection accepted
Sim_NM_Write Socket is writeable, or outgoing connection has completed

Socket notifiers of the mode Sim_NM_Write are not guaranteed to be called again unless a previous attempt to send data to the socket failed for flow control reasons (that is, it would have blocked).

This means that notifiers of that mode should only be enabled for waiting on the completion of a nonblocking outgoing connection or for a previously "full" socket to accept data again.

Linux only: SIM_notify_on_descriptor will call a registered callback depending on mode for a given file descriptor in a way similar to SIM_notify_on_socket.

Windows only: SIM_notify_on_object will call a registered callback when object (which must be a waitable object) is in signalled state. The signalling object is modified in the same way as the Windows wait functions (WaitForMultipleObjects etc).

Note: A notification should be removed before its socket or descriptor is closed.
Note: On Windows, sockets registered for notification become nonblocking and must remain so for as long as they are registered. This is a limitation of the underlying Win32 API.
EXECUTION CONTEXT
Cell Context (call); Threaded Context (callback with nonzero run_in_thread); Global Context (callback otherwise)
SEE ALSO
SIM_thread_safe_callback

SIM_realtime_event()

NAME
SIM_realtime_event — schedule callback in host time
SYNOPSIS
int64
SIM_realtime_event(unsigned delay, void (*NOTNULL callback)(lang_void *data),
                   lang_void *data, int run_in_thread, const char *desc);

DESCRIPTION
Register callback to be run in delay ms, with argument data. The delay is in real time (on the host machine), and the actual delay may be somewhat larger because of host scheduling.

If run_in_thread is 1, the callback may be run in a thread where it cannot access or call anything in Simics except for SIM_thread_safe_callback. If run_in_thread is zero, the callback function is always run in Global Context, with the simulation temporarily suspended and the entire Simics API available. This may cause the call to occur slightly later than requested, depending on what Simics is doing at the time.

Values other than 0 and 1 for run_in_thread are reserved.

The desc parameter is only present for debugging and has no other effect; it should be a static string describing the callback but may also be left NULL if desired.

The callback is only called once.

The return value is a non-zero identifier that can be used to cancel the callback using SIM_cancel_realtime_event.

EXECUTION CONTEXT
Cell Context. The callback is called in Threaded Context if run_in_thread is nonzero, in Global Context otherwise.
SEE ALSO
SIM_cancel_realtime_event, SIM_thread_safe_callback

SIM_register_work()

NAME
SIM_register_work — register function to be called in Global Context
SYNOPSIS
void
SIM_register_work(void (*NOTNULL f)(lang_void *data), lang_void *data);

DESCRIPTION
Register work to be done in Global Context as soon as possible, (but not during the call to SIM_register_work itself). This function is also useful for doing work without blocking a notifier.

In general, the function SIM_run_alone should be used instead of this function when a callback is posted from Cell Context. The reason is that SIM_run_alone, but not SIM_register_work, guarantees that the callback is executed before the next instruction is dispatched.

EXECUTION CONTEXT
Cell Context (call); Global Context (callback)

SIM_run_async_work()

NAME
SIM_run_async_work — launch asynchronous work in a separate thread
SYNOPSIS
void
SIM_run_async_work(lang_void *(*NOTNULL async_call)(lang_void *arg),
                   void (*async_ready)(lang_void *async_ret, lang_void *arg),
                   lang_void *arg);

DESCRIPTION
SIM_run_async_work creates a new thread, running in parallel with the Simics main thread, where the async_call function will be called. Since the function runs in Threaded Context, most Simics API functions, except, e.g., SIM_thread_safe_callback, are not be available. Once the async_call function has run, its return value is passed to async_ready, if supplied, that will be called in Global Context, i.e. in the Simics main thread.

The user supplied arg parameter is passed unmodified to both callback functions.

SIM_run_async_work is typically used when calling functions that would block the main thread for a long time while obtaining their result.

If the result of SIM_run_async_work is used in the simulation, it should be sent through a recorder to make sure that the session can be replayed. This is needed for features such as reverse execution to work. See the recorder module and the recorder_v2 interface for more information.

EXAMPLE
import socket

def async_call(arg):
    # runs in separate thread without blocking Simics
    return socket.gethostbyname(arg)

def async_ready(ret, arg):
    # runs in Simics main thread with access to the full Simics API
    print("Host %s has IP address %s" % (arg, ret))

simics.SIM_run_async_work(async_call, async_ready, "www.intel.com")

EXECUTION CONTEXT
Cell Context (call); Threaded Context (async_call callback); Global Context (async_ready callback)
SEE ALSO
SIM_notify_on_descriptor, SIM_notify_on_object, SIM_notify_on_socket, SIM_thread_safe_callback, SIM_run_alone, SIM_run_unrestricted

SIM_run_in_thread()

NAME
SIM_run_in_thread — run function in a separate thread
SYNOPSIS
void
SIM_run_in_thread(void (*NOTNULL f)(lang_void *arg), lang_void *arg);

DESCRIPTION
SIM_run_in_thread schedules the callback f to run on a separate thread. The callback will run in Threaded Context and must observe the associated restrictions.

Simics maintains a pool of worker threads used by this function, and hence the callback can typically be started quickly.

The callback is allowed to block or otherwise run for a long time.

The user supplied arg parameter is passed unmodified to the callback.

EXECUTION CONTEXT
Any thread context (call); Threaded Context (callback);
SEE ALSO
SIM_run_async_work, SIM_run_alone

SIM_thread_safe_callback()

NAME
SIM_thread_safe_callback — register function to be called in Global Context
SYNOPSIS
void
SIM_thread_safe_callback(void (*NOTNULL f)(lang_void *data), lang_void *data);

DESCRIPTION
This is the function in the Simics API that can be called from threads that are not created by Simics (i.e., from Threaded context).

When the callback is run, it is executed in Global Context, which means that it is safe to call any API functions from it. Another thread in the module may at this time also call API functions, if it synchronizes correctly with the callback function. For example, the callback function might just signal to the foreign thread to do its Simics API calls, wait for the thread to signal that it has finished, and then return.

EXECUTION CONTEXT
Threaded context (call); Global Context (callback)

Simulator Translation Caches

SIM_STC_flush_cache()

NAME
SIM_STC_flush_cache, SIM_flush_I_STC_logical, SIM_flush_D_STC_logical, SIM_flush_I_STC_physical, SIM_flush_D_STC_physical — flush or remove entries in the STCs of a cpu
SYNOPSIS
void
SIM_STC_flush_cache(conf_object_t *NOTNULL cpu);

void
SIM_flush_I_STC_logical(conf_object_t *NOTNULL cpu,
			logical_address_t vaddr,
                        logical_address_t length);

void
SIM_flush_D_STC_logical(conf_object_t *NOTNULL cpu,
			logical_address_t vaddr,
                        logical_address_t length);

void
SIM_flush_I_STC_physical(conf_object_t *NOTNULL cpu,
                         physical_address_t paddr,
                         physical_address_t length);

void
SIM_flush_D_STC_physical(conf_object_t *NOTNULL cpu,
                         physical_address_t paddr,
                         physical_address_t length,
                         read_or_write_t read_or_write);

DESCRIPTION
These functions remove entries from the Simics internal caches (STCs) or completely flushes the STCs contents. Memory mappings which have been cached in the STCs will be faster for Simics to execute. Simics extensions such as a cache model will need to flush entries in the STC when a cache line is replaced, in order to be called when a cache line is used again.

SIM_STC_flush_cache flushes the entire contents of the STCs (both instruction and data) from the specified cpu.

The SIM_flush_xxx functions removes specified memory ranges in the instruction or data STC. The address range is either the logical or the physical address. The read_or_write parameter specifies whether the read or the write D-STC should be flushed. If the function doesn't have such a parameter, both read and write D-STCs are flushed. The flushed address range is at least [ vaddr ... (vaddr + length − 1) ], but may be larger. SIM_flush_D_STC_logical currently always flushes an entire page.

The SIM_flush_xxx functions can only be used on CPUs that implement the internal stc interface; hence, they can not be used on user-defined CPU models.

EXECUTION CONTEXT
Cell Context

SIM_flush_all_caches()

NAME
SIM_flush_all_caches — clear Simics's internal caches
SYNOPSIS
void
SIM_flush_all_caches(void);

DESCRIPTION
Clears Simics's internal caches such as STC contents and intermediate code. This function is mainly for internal use (for debugging purposes) and may be removed in the future.
EXECUTION CONTEXT
Global Context

SIM_flush_cell_caches()

NAME
SIM_flush_cell_caches — clear internal caches for a given cell
SYNOPSIS
void
SIM_flush_cell_caches(conf_object_t *NOTNULL obj);

DESCRIPTION
Clears internal caches in Simics for a given cell, such as STC contents and intermediate code.
EXECUTION CONTEXT
Cell Context

Stalling

SIM_stall_count()

NAME
SIM_stall_count — get number of cycles a processor has been stalled
SYNOPSIS
cycles_t
SIM_stall_count(conf_object_t *NOTNULL obj);

DESCRIPTION
SIM_stall_count returns the total number of cycles the processor associated to obj has been stalled.
RETURN VALUE
Returns the total number of cycles the processor associated with obj has been stalled.
EXECUTION CONTEXT
Cell Context

SIM_stall_cycle()

NAME
SIM_stall_cycle, SIM_stall — stall execution a specified number of cycles
SYNOPSIS
void
SIM_stall_cycle(conf_object_t *NOTNULL obj, cycles_t cycles);

void
SIM_stall(conf_object_t *NOTNULL obj, double seconds);

DESCRIPTION
SIM_stall_cycle and SIM_stall set the stall duration of the processor obj. The stall duration is given in clock cycles or seconds and is how long obj will stall before resuming its normal activity. If obj was already stalling, the time remaining is changed. A zero stall duration is a request to cease stalling immediately.

The specified duration is interpreted as relative the local time of obj.

obj must implement the stall and cycle interfaces.

EXECUTION CONTEXT
Cell Context
EXCEPTIONS
SimExc_General Thrown if cycles or seconds is negative.

SEE ALSO
SIM_stalled_until, SIM_stall_count

SIM_stalled_until()

NAME
SIM_stalled_until — query how many cycles that remains of stall
SYNOPSIS
cycles_t
SIM_stalled_until(conf_object_t *NOTNULL obj);

DESCRIPTION
SIM_stalled_until returns how many more cycles the processor will stall before the associated processor starts to execute instructions again.
EXECUTION CONTEXT
Cell Context

Time and Events

SIM_get_global_message()

NAME
SIM_get_global_message — obtain current global message
SYNOPSIS
const char *
SIM_get_global_message(void *ref);

DESCRIPTION
Return the global message currently being triggered, if ref does not match the reference of the source trigger, otherwise return NULL.

This function must only be called from a callback of the global notifier Sim_Global_Notify_Message.

EXECUTION CONTEXT
Global Context
SEE ALSO
SIM_trigger_global_message

SIM_run_alone()

NAME
SIM_run_alone — run callback with all execution stopped
SYNOPSIS
void
SIM_run_alone(void (*NOTNULL f)(lang_void *data), lang_void *data);

DESCRIPTION
SIM_run_alone will make sure that the callback f, passed as argument, will be run in a context where all execution threads are stopped and the full Simics API is available (Global Context). This is useful for temporarily stopping the simulation to run API functions not allowed in Cell Context.

If the callback is posted while an instruction is being emulated then the callback be invoked when the current instruction has completed and before the next instruction is dispatched.

Although no other execution threads are running when the callback is invoked, their exact position in simulated time may vary between runs. If the callback accesses objects in cells other than the one that SIM_run_alone was called from, then care must be taken to preserve determinism.

EXECUTION CONTEXT
All contexts including Threaded Context (call); Global Context (callback)
SEE ALSO
SIM_run_unrestricted

SIM_trigger_global_message()

NAME
SIM_trigger_global_message — queue up a global message
SYNOPSIS
void
SIM_trigger_global_message(const char *msg, void *ref);

DESCRIPTION
This queues up a global message, which will be dispatched shortly in global context, to all listeners of the Sim_Global_Notify_Message global notifier. The ref parameter is the reference of the source, or NULL to dispatch to all listeners.

The notifier callbacks should use SIM_get_global_message to retrieve the message. Only callbacks that provide a NULL reference or a reference different from ref will obtain the message.

EXECUTION CONTEXT
All contexts including Threaded Context
SEE ALSO
SIM_get_global_message

User Interface

SIM_call_python_function()

NAME
SIM_call_python_function — call a Python named function
SYNOPSIS
attr_value_t
SIM_call_python_function(const char *NOTNULL func, attr_value_t *NOTNULL args);

DESCRIPTION
Calls the Python function named func with arguments in args, which must be a list.

The namespace searched for func is the same as the Simics commands @ and python use; i.e., the Python module __main__. You may want to use a module-relative name for func such as __builtin__.repr when calling functions not defined at the Simics command-line. This avoids calling any local redefinition of that function.

EXCEPTIONS
SimExc_Type Thrown if args is not list or cannot be converted to Python or if func is not callable or if the return value cannot be converted to an attr_value_t.

SimExc_Lookup Thrown if func does not exist.
SimExc_General Thrown if there was an error executing Python code.
SimExc_Break Thrown on user interrupt.

RETURN VALUE
Return value of the Python function
EXECUTION CONTEXT
Cell Context
SEE ALSO
SIM_make_attr_list, SIM_run_python

SIM_get_api_function()

NAME
SIM_get_api_function — return an API function by name
SYNOPSIS
api_function_t
SIM_get_api_function(const char *function);

DESCRIPTION
Looks up a C function in the Simics API based on its name and returns a pointer to it. Typically used to access a function added to the Simics API in an update release (minor version) while remaining binary compatible with older versions of Simics.

The pre-processor macro GET_API_FUNCTION provides wrapping of SIM_get_api_function for simpler type casting.

SIM_get_api_function is neither available nor needed in Python. To access a new function in a backward compatible way there, the build id can be used to write conditional code, see example below.

EXAMPLE
A new function SIM_foo is introduced in the Simics release with build id 5234. Since older versions of Simics do not have this function, a module writer that wants to use it while remaining compatible with old Simics versions, can write the following:
    GET_API_FUNCTION(tmp_SIM_foo, SIM_foo);
    if (tmp_SIM_foo != NULL)
        tmp_SIM_foo(1);
    else
        // code for older versions
   

Once compatibility with versions before build id 5234 can be dropped, the code in the example is simply replaced with a direct call to SIM_foo.

The corresponding implementation in Python is:

    if hasattr(simics, 'SIM_foo'):
        SIM_foo(1)
    else:
        # code for older versions
   

Or alternatively:

    if conf.sim.build_id >= 5234:
        SIM_foo(1)
    else:
        # code for older versions
   

RETURN VALUE
Returns a pointer to the API function if it exists or zero. The return type api_function_t is defined as:
typedef void (*api_function_t)(void);

EXECUTION CONTEXT
Cell Context

SIM_get_batch_mode()

NAME
SIM_get_batch_mode — return setting of the batch-mode
SYNOPSIS
bool
SIM_get_batch_mode(void);

DESCRIPTION
This function returns the current value of Simics's batch-mode flag.
EXECUTION CONTEXT
Cell Context

SIM_get_debugger()

NAME
SIM_get_debugger — return the debugger object
SYNOPSIS
conf_object_t *
SIM_get_debugger(void);

DESCRIPTION
Returns the Simics Debugger. The returned object is the object which implements the Simics Debugger API. The debugger object is created if it does not already exist. Returns NULL and signals an exception if the debugger could not be created.
RETURN VALUE
Returns the debugger object
EXCEPTIONS
SimExc_General Thrown if the debugger could not be created.
EXECUTION CONTEXT
Global Context

SIM_load_target()

NAME
SIM_load_target — load Simics target from file
SYNOPSIS
attr_value_t
SIM_load_target(const char *NOTNULL target,
                const char *ns, attr_value_t presets,
                attr_value_t cmdline_args);

DESCRIPTION
Load the target target into Simics. This can either be a file name or a target name, as returned by the list-targets command.

This function is functionally equivalent to invoking the script by passing it as a command line argument or to running the script with the load-target or run-script command, with the local flag set.

The ns and presets arguments have the same semantics as namespace and presets arguments to the run-script command.

The cmdline_args argument should be a list of 2-element lists of target parameters [name, value].

EXCEPTIONS
SimExc_Break Thrown if the script was interrupted by the user.

SimExc_General Thrown if the script was interrupted by an error.

SimExc_IOError Thrown if the script file could not be opened.

EXECUTION CONTEXT
Global Context

SIM_quit()

NAME
SIM_quit — quit Simics
SYNOPSIS
void
SIM_quit(int exit_code);

DESCRIPTION
Quit Simics in an orderly fashion. The Simics process will return the value exit_code. See the Core_Clean_At_Exit and Core_At_Exit haps for ways to run user code when Simics exits. Callbacks for the Core_Clean_At_Exit hap will only run if SIM_quit is called from Global Context, while Core_At_Exit is always called.
EXECUTION CONTEXT
Cell Context. Global Context if possible.

SIM_run_command()

NAME
SIM_run_command — evaluate a CLI command
SYNOPSIS
attr_value_t
SIM_run_command(const char *NOTNULL line);

DESCRIPTION
Runs a CLI command and returns the value, if any, as an attr_value_t.
EXCEPTIONS
SimExc_General Thrown if there was an error executing the CLI command.

SimExc_Type Thrown if the return value could not be converted to an attr_value_t.

EXECUTION CONTEXT
Global Context

SIM_run_command_file()

NAME
SIM_run_command_file, SIM_run_command_file_params — read CLI commands from file
SYNOPSIS
void
SIM_run_command_file(const char *NOTNULL file, bool local);

void
SIM_run_command_file_params(const char *NOTNULL file, bool local,
                            attr_value_t params);

DESCRIPTION
Read and execute the script file file; i.e., execute each line in the file as if it was typed at the Simics prompt.

This function is functionally equivalent to invoking the script by passing it as a command line argument or to running the script with the run-command-file command.

If local is true, the script will run with its own copy of all global CLI variables. When the script has finished executing, the previous variable set is restored.

The params argument can be used to pass parameters to the script. It must be a list of name-value pairs of strings, for example, from Python it could be [["num_cores", "4"], ["memory_megs", "1024"]].

EXCEPTIONS
SimExc_Break Thrown if the script was interrupted by the user.

SimExc_General Thrown if the script was interrupted by an error.

SimExc_IOError Thrown if the script file could not be opened.

EXECUTION CONTEXT
Global Context

SIM_run_python()

NAME
SIM_run_python — run a Python expression
SYNOPSIS
attr_value_t
SIM_run_python(const char *NOTNULL line);

DESCRIPTION
SIM_run_python runs a Python expression or statement. The return value, if any, is converted to a Simics attribute value. If line is a statement, a NIL attribute is returned.
EXCEPTIONS
SimExc_General Thrown if there was an error executing Python code.

SimExc_Type Thrown if the return value could not be converted to an attr_value_t.

SimExc_Break Thrown on user interrupt.

SEE ALSO
SIM_call_python_function
EXECUTION CONTEXT
Cell Context

SIM_shutdown()

NAME
SIM_shutdown — shutdown Simics
SYNOPSIS
void
SIM_shutdown(void);

DESCRIPTION
Perform the same clean up as SIM_quit, but do not exit the process. After having called this function, no Simics API function can be called.
EXECUTION CONTEXT
Cell Context. Global Context if possible.

SIM_source_python()

NAME
SIM_source_python, SIM_source_python_in_module — execute Python source file
SYNOPSIS
void
SIM_source_python(const char *NOTNULL file);

void
SIM_source_python_in_module(const char *NOTNULL file,
                            const char *NOTNULL module);

DESCRIPTION
SIM_source_python executes Python from file in the global Python scope. SIM_source_python_in_module is similar but executes the file contents in a named Python module.
EXCEPTIONS
SimExc_General Thrown if there was an error executing Python code.

SimExc_IOError Thrown if there was an error opening the file.

SimExc_Break Thrown on user interrupt.

EXECUTION CONTEXT
Global Context

6.1 Simulator API Data Types 7 Simulator-to-Simulator Interfaces