T-EMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Typedefs | Functions
Cpu.h File Reference
#include <stdint.h>
Include dependency graph for Cpu.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* temu_SparcAsrHandler )(void *Cpu, uint32_t Instr)
 
typedef void(* temu_SafeCb )(void *)
 

Functions

uint64_t temu_cpuGetFreq (void *Cpu)
 Get the clock frequency for the CPU. More...
 
void temu_cpuSetPc (void *Cpu, uint64_t Pc)
 Set the program counter. More...
 
uint64_t temu_cpuGetPc (void *Cpu)
 Get the program counter. More...
 
void temu_cpuReset (void *Cpu, int ResetType)
 Reset the processor. More...
 
uint64_t temu_cpuRun (void *Cpu, uint64_t Cycles)
 Run the processor for a number of cycles. More...
 
uint64_t temu_cpuStep (void *Cpu, uint64_t Steps)
 Run the processor for a number of steps. More...
 
uint64_t temu_cpuGetReg (void *Cpu, unsigned Reg)
 
void temu_cpuSetReg (void *Cpu, unsigned Reg, uint64_t Value)
 
float temu_cpuGetFpr32 (void *Cpu, unsigned Reg)
 
uint32_t temu_cpuGetFpr32Bits (void *Cpu, unsigned Reg)
 
void temu_cpuSetFpr32 (void *Cpu, unsigned Reg, float Value)
 
void temu_cpuSetFpr32Bits (void *Cpu, unsigned Reg, uint32_t Value)
 
double temu_cpuGetFpr64 (void *Cpu, unsigned Reg)
 
uint64_t temu_cpuGetFpr64Bits (void *Cpu, unsigned Reg)
 
void temu_cpuSetFpr64 (void *Cpu, unsigned Reg, double Value)
 
void temu_cpuSetFpr64Bits (void *Cpu, unsigned Reg, uint64_t Value)
 
void temu_cpuEnableTraps (void *Cpu)
 
void temu_cpuDisableTraps (void *Cpu)
 
int temu_sparcGetWindowCount (void *Cpu)
 
uint32_t temu_sparcGetWindowedReg (void *Cpu, int Window, unsigned Reg)
 
void temu_sparcSetWindowedReg (void *Cpu, int Window, unsigned Reg, uint32_t Value)
 
void temu_sparcSetY (void *Cpu, uint64_t Value)
 
uint64_t temu_sparcGetY (void *Cpu)
 
void temu_sparcSetAsr (void *Cpu, unsigned Reg, uint64_t Value)
 
uint64_t temu_sparcGetAsr (void *Cpu, unsigned Reg)
 
void temu_sparcSetAsrWriter (void *Cpu, unsigned Asr, temu_SparcAsrHandler Handler)
 
void temu_sparcSetAsrReader (void *Cpu, unsigned Asr, temu_SparcAsrHandler Handler)
 
void temu_sparcSetPsr (void *Cpu, uint32_t Value)
 
uint32_t temu_sparcGetPsr (void *Cpu)
 
void temu_sparcSetTbr (void *Cpu, uint32_t Value)
 
uint32_t temu_sparcGetTbr (void *Cpu)
 
void temu_sparcSetWim (void *Cpu, uint32_t Value)
 
uint32_t temu_sparcGetWim (void *Cpu)
 
void temu_sparcSetNPc (void *Cpu, uint32_t Value)
 
uint32_t temu_sparcGetNPc (void *Cpu)
 
void temu_machineReset (void *Machine, int ResetType)
 Reset the Machine. More...
 
uint64_t temu_machineRun (void *Machine, uint64_t NanoSecs)
 Run the machine for a number of nanoseconds. More...
 
void temu_postCallback (void *Obj, temu_SafeCb Cb, void *Arg)
 

Typedef Documentation

typedef void(* temu_SafeCb)(void *)

Post a callback in a CPU or Machine object (implementing the EventIface).

The posting will be thread-safe and the callback will be excuted by the main thread (the one calling the cpu or machine run / step functions). The main thread is the thread calling cpu run if there is only a single cpu in the system, and the thread calling machine run if there are multiple CPUs in the system.

The callback will be executed as soon as possible, when the even queue is checked for events. Which in practice mean:

  • At the end of the current time quanta for multi-cpu systems.
  • At regular intervals for single CPU systems (a CPU runs a null-event at a rate of 1kHz simulated real-time (though this rate is not guaranteed for the future)), but the callback will be called as soon as a normal event is executed.

The posting of this callback is thread-safe but not async / signal safe. I.e. do not do this from signal handler or async io callbacks.

When the event is executed, it is safe to do most emulator operations, including posting of events, calling API functions, etc.

The callback must however not:

  • Manipulate the object system meta state (i.e. creating or modifying classes)
  • Replace signal handlers (e.g. SIGINT)
  • Run or step the emulator in any way (e.g. by calling machineRun(), cpuRun() or using the CpuIface or MachineIface interfaces.

Definition at line 259 of file Cpu.h.

typedef void(* temu_SparcAsrHandler)(void *Cpu, uint32_t Instr)

Definition at line 156 of file Cpu.h.

Function Documentation

void temu_cpuDisableTraps ( void *  Cpu)
void temu_cpuEnableTraps ( void *  Cpu)
float temu_cpuGetFpr32 ( void *  Cpu,
unsigned  Reg 
)
uint32_t temu_cpuGetFpr32Bits ( void *  Cpu,
unsigned  Reg 
)
double temu_cpuGetFpr64 ( void *  Cpu,
unsigned  Reg 
)
uint64_t temu_cpuGetFpr64Bits ( void *  Cpu,
unsigned  Reg 
)
uint64_t temu_cpuGetFreq ( void *  Cpu)

Get the clock frequency for the CPU.

Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
Returns
The configured clock frequency in Hz.
uint64_t temu_cpuGetPc ( void *  Cpu)

Get the program counter.

The program counter will be returned.

Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
Returns
The value of the program counter register
uint64_t temu_cpuGetReg ( void *  Cpu,
unsigned  Reg 
)
void temu_cpuReset ( void *  Cpu,
int  ResetType 
)

Reset the processor.

Resetting the CPU will result in a reset cascade where all connected devices are also reset.

Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
ResetTypeThe type of reset, by convention 0 means cold reset, and 1 indicates a warm reset.
uint64_t temu_cpuRun ( void *  Cpu,
uint64_t  Cycles 
)

Run the processor for a number of cycles.

The function runs the processor for a number of cycles. If you wish to run the processor with another time unit, you can compute the cycles from the clock frequency of the emulated processor.

In case the processor halts or enters idle mode and there are no pending events the function will return early.

Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
CyclesThe number of cycles to run the processor for.
Returns
The number of executed cycles.
void temu_cpuSetFpr32 ( void *  Cpu,
unsigned  Reg,
float  Value 
)
void temu_cpuSetFpr32Bits ( void *  Cpu,
unsigned  Reg,
uint32_t  Value 
)
void temu_cpuSetFpr64 ( void *  Cpu,
unsigned  Reg,
double  Value 
)
void temu_cpuSetFpr64Bits ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)
void temu_cpuSetPc ( void *  Cpu,
uint64_t  Pc 
)

Set the program counter.

The program counter will be set to the supplied value.

Note
For targets with delay slots (SPARC, MIPS etc), the function will also set the next PC to PC + sizeof(instruction).
Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
PcThe program counter.
void temu_cpuSetReg ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)
uint64_t temu_cpuStep ( void *  Cpu,
uint64_t  Steps 
)

Run the processor for a number of steps.

This function is different from temu_cpuRun, which runs for a time. The steps here indicates instructions executed (including trapping instructions). This can be contrasted to the run function which may advance the cycle counter by more than one for an instruction (depending on the timing models).

The function may return early in case the processor halts its execution or has entered idle mode and there are no events pending.

Warning
In case the Cpu does not implement the CpuIface the program will abort. Do not use this function in performance critical code!!!
Parameters
CpuThe CPU object
StepsThe number of steps to run the processor for.
Returns
The number of executed steps.
void temu_machineReset ( void *  Machine,
int  ResetType 
)

Reset the Machine.

Resetting the Machine will result in a reset cascade where all connected devices and processors are also reset.

Warning
In case the Machine does not implement the MachineIface the program will abort. Do not use this function in performance critical code!!!
Parameters
MachineThe Machine object
ResetTypeThe type of reset, by convention 0 means cold reset, and 1 indicates a warm reset.
uint64_t temu_machineRun ( void *  Machine,
uint64_t  NanoSecs 
)

Run the machine for a number of nanoseconds.

The function runs the machine and for a number of nanoseconds. This will run all the CPUs in the system.

In case a processor halts or enters idle mode, the function returns early.

Warning
In case the machine does not implement the MachineIface the program will abort. Do not use this function in performance critical code!!!
Parameters
MachineThe machine object
NanoSecsThe number of nanosecs to run each processor for.
Returns
The number of executed nanoseconds.
void temu_postCallback ( void *  Obj,
temu_SafeCb  Cb,
void *  Arg 
)
uint64_t temu_sparcGetAsr ( void *  Cpu,
unsigned  Reg 
)
uint32_t temu_sparcGetNPc ( void *  Cpu)
uint32_t temu_sparcGetPsr ( void *  Cpu)
uint32_t temu_sparcGetTbr ( void *  Cpu)
uint32_t temu_sparcGetWim ( void *  Cpu)
int temu_sparcGetWindowCount ( void *  Cpu)
uint32_t temu_sparcGetWindowedReg ( void *  Cpu,
int  Window,
unsigned  Reg 
)
uint64_t temu_sparcGetY ( void *  Cpu)
void temu_sparcSetAsr ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)
void temu_sparcSetAsrReader ( void *  Cpu,
unsigned  Asr,
temu_SparcAsrHandler  Handler 
)
void temu_sparcSetAsrWriter ( void *  Cpu,
unsigned  Asr,
temu_SparcAsrHandler  Handler 
)
void temu_sparcSetNPc ( void *  Cpu,
uint32_t  Value 
)
void temu_sparcSetPsr ( void *  Cpu,
uint32_t  Value 
)
void temu_sparcSetTbr ( void *  Cpu,
uint32_t  Value 
)
void temu_sparcSetWim ( void *  Cpu,
uint32_t  Value 
)
void temu_sparcSetWindowedReg ( void *  Cpu,
int  Window,
unsigned  Reg,
uint32_t  Value 
)
void temu_sparcSetY ( void *  Cpu,
uint64_t  Value 
)