TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Simulator.h File Reference
#include "temu-c/Support/Attributes.h"
#include "temu-c/Target/Cpu.h"
#include <stdint.h>
Include dependency graph for Simulator.h:

Go to the source code of this file.

Functions

TEMU_API void temu_simSetQuanta (int64_t Ns)
 
TEMU_API int64_t temu_simGetTime (void)
 
temu_CpuExitReason temu_simRunNanos (int64_t Nanos, bool Detatched)
 
temu_CpuExitReason temu_simRunCycles (int Cpu, int64_t Cycles, bool Detatched)
 
temu_CpuExitReason temu_simRunSecs (double Secs, bool Detatched)
 
int temu_simIsRunning (void)
 
TEMU_API temu_CpuExitReason temu_simStep (int Cpu, uint64_t Steps)
 
TEMU_API int temu_simGetCurrentCpu (void)
 
TEMU_API int temu_simGetCpuCount (void)
 
void temu_simStop (void)
 
void temu_simRunCallback (void(*Func)(void *), void *Data)
 
temu_CpuExitReason temu_simGetExitReason ()
 

Function Documentation

TEMU_API int temu_simGetCpuCount ( void  )

Get the number of CPUs in the simulator.

Returns
Number of CPUs
TEMU_API int temu_simGetCurrentCpu ( void  )

Get the id of the current CPU for the simulator.

Returns
CPU id of the current CPU
temu_CpuExitReason temu_simGetExitReason ( )

Get the last exit reason for the simulator

This can be used to query the last exit result for the run and step functions.

Returns
Exit reason from last call.
TEMU_API int64_t temu_simGetTime ( void  )

Get current time of simulator in nanoseconds.

The simulator time will in normal cases be adjusted to be a multiple of the quanta, but as quantas are dynamically adjusted when executing synchronised events, and when the last quanta is executed, you cannot rely on the time being a multiple of the quanta.

Returns
Current time in nanoseconds
int temu_simIsRunning ( void  )

Return 0 if sim is not running, non-zero otherwise.

void temu_simRunCallback ( void(*)(void *)  Func,
void *  Data 
)

Execute a callback

The function will run the callback in the current thread if the simulator is not running, otherwise it will post it as a thread-safe callback which will be called a bit later during emulator event processing.

Parameters
FuncFunction to invoke
DataPointer to pass to Func
temu_CpuExitReason temu_simRunCycles ( int  Cpu,
int64_t  Cycles,
bool  Detatched 
)
temu_CpuExitReason temu_simRunNanos ( int64_t  Nanos,
bool  Detatched 
)

Run the simulator for the given amount of nanoseconds

Parameters
NanosNanoseconds to run the simulator
DetatchedSet to true to run in a separate thread.
Returns
Exit reason of the last executed CPU. Under normal conditions this is teCER_Normal, but may be other values in-case breakpoints are hit.
temu_CpuExitReason temu_simRunSecs ( double  Secs,
bool  Detatched 
)
TEMU_API void temu_simSetQuanta ( int64_t  Ns)

Set the quanta of the simulator in nanoseconds.

The quanta is used when scheduling processors. It is essentially identical to the machine class quanta property. Effectively, each processor in the system will synchronise with the other processors and ensure that their timers are identical (within a small tolerance, as a CPU will run until the quanta end plus the slack introduced by the last instruction). Note that the quantas are set in nanoseconds as cycles are inappropriate when multiple processors of different clocks frequencies are used. Note that runtime quantas are adapted based on when synchronised events occur, and for the last quanta when running the processor.

Parameters
NsNanoseconds of quanta
TEMU_API temu_CpuExitReason temu_simStep ( int  Cpu,
uint64_t  Steps 
)

Step the CPU for a number of steps.

The function will step the CPU with the provided CPU number for a number of steps. A step is defined to be equal to one instruction, or one time advancement in case the CPU is in idle mode or halted.

Note that it is not necessarily so that the CPU id in question is still the current CPU when the function returns. Other CPUs may for example hit a breakpoint or enter halt/error-mode.

Parameters
CpuCPU number to step
StepsNumber of steps to run.
Returns
Exit reason of the last executed CPU.
void temu_simStop ( void  )

Stop the simulator.

Returns after the simulator has stopped.