TEMU  2
The Terma Emulator
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Cpu.h File Reference
#include "temu-c/Support/Attributes.h"
#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

TEMU_API uint64_t temu_cpuGetFreq (void *Cpu)
 Get the clock frequency for the CPU. More...
 
TEMU_API void temu_cpuSetPc (void *Cpu, uint64_t Pc)
 Set the program counter. More...
 
TEMU_API uint64_t temu_cpuGetPc (void *Cpu)
 Get the program counter. More...
 
TEMU_API void temu_cpuReset (void *Cpu, int ResetType)
 Reset the processor. More...
 
TEMU_API uint64_t temu_cpuRun (void *Cpu, uint64_t Cycles)
 Run the processor for a number of cycles. More...
 
TEMU_API uint64_t temu_cpuStep (void *Cpu, uint64_t Steps)
 Run the processor for a number of steps. More...
 
TEMU_API int temu_cpuTranslateAddress (void *Cpu, uint64_t Va, uint32_t flags, uint64_t *physAddressResult)
 temu_cpuTranslateAddress Uses the MMU to translate the given virtual address Va to the physical address in the emulator More...
 
TEMU_API uint64_t temu_cpuGetReg (void *Cpu, unsigned Reg)
 
TEMU_API void temu_cpuSetReg (void *Cpu, unsigned Reg, uint64_t Value)
 
TEMU_API float temu_cpuGetFpr32 (void *Cpu, unsigned Reg)
 
TEMU_API uint32_t temu_cpuGetFpr32Bits (void *Cpu, unsigned Reg)
 
TEMU_API void temu_cpuSetFpr32 (void *Cpu, unsigned Reg, float Value)
 
TEMU_API void temu_cpuSetFpr32Bits (void *Cpu, unsigned Reg, uint32_t Value)
 
TEMU_API double temu_cpuGetFpr64 (void *Cpu, unsigned Reg)
 
TEMU_API uint64_t temu_cpuGetFpr64Bits (void *Cpu, unsigned Reg)
 
TEMU_API void temu_cpuSetFpr64 (void *Cpu, unsigned Reg, double Value)
 
TEMU_API void temu_cpuSetFpr64Bits (void *Cpu, unsigned Reg, uint64_t Value)
 
TEMU_API void temu_cpuEnableTraps (void *Cpu)
 
TEMU_API void temu_cpuDisableTraps (void *Cpu)
 
TEMU_API void temu_cpuRaiseTrap (void *Cpu, int Trap, unsigned Flags)
 
TEMU_API int temu_sparcGetWindowCount (void *Cpu)
 
TEMU_API uint32_t temu_sparcGetWindowedReg (void *Cpu, int Window, unsigned Reg)
 
TEMU_API void temu_sparcSetWindowedReg (void *Cpu, int Window, unsigned Reg, uint32_t Value)
 
TEMU_API void temu_sparcSetY (void *Cpu, uint64_t Value)
 
TEMU_API uint64_t temu_sparcGetY (void *Cpu)
 
TEMU_API void temu_sparcSetAsr (void *Cpu, unsigned Reg, uint64_t Value)
 
TEMU_API uint64_t temu_sparcGetAsr (void *Cpu, unsigned Reg)
 
TEMU_API void temu_sparcSetAsrWriter (void *Cpu, unsigned Asr, temu_SparcAsrHandler Handler)
 
TEMU_API void temu_sparcSetAsrReader (void *Cpu, unsigned Asr, temu_SparcAsrHandler Handler)
 
TEMU_API void temu_sparcSetPsr (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_sparcGetPsr (void *Cpu)
 
TEMU_API void temu_sparcSetTbr (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_sparcGetTbr (void *Cpu)
 
TEMU_API void temu_sparcSetWim (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_sparcGetWim (void *Cpu)
 
TEMU_API void temu_sparcSetNPc (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_sparcGetNPc (void *Cpu)
 
TEMU_API void temu_armSetAPSR (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_armGetAPSR (void *Cpu)
 
TEMU_API void temu_armSetFPSCR (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_armGetFPSCR (void *Cpu)
 
TEMU_API void temu_armSetFPEXC (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_armGetFPEXC (void *Cpu)
 
TEMU_API void temu_armSetFPINST (void *Cpu, int Idx, uint32_t Value)
 
TEMU_API uint32_t temu_armGetFPINST (void *Cpu, int Idx)
 
TEMU_API unsigned temu_armGetExecMode (void *Cpu)
 
TEMU_API void temu_armSetExecMode (void *Cpu, unsigned Mode)
 
TEMU_API void temu_ppcSetCrReg (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_ppcGetCrReg (void *Cpu)
 
TEMU_API void temu_ppcSetXerReg (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_ppcGetXerReg (void *Cpu)
 
TEMU_API void temu_ppcSetMsrReg (void *Cpu, uint64_t Value)
 
TEMU_API uint64_t temu_ppcGetMsrReg (void *Cpu)
 
TEMU_API void temu_ppcSetReserveAddress (void *Cpu, uint64_t reserveAddress)
 
TEMU_API uint64_t temu_ppcGetReserveAddress (void *Cpu)
 
TEMU_API void temu_ppcClearAddressReservation (void *Cpu)
 
TEMU_API int temu_ppcIsReservationBitSet (void *Cpu)
 
TEMU_API void temu_ppcSetCtrReg (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_ppcGetCtrReg (void *Cpu)
 
TEMU_API void temu_ppcSetFpscrReg (void *Cpu, uint32_t Value)
 
TEMU_API uint32_t temu_ppcGetFpscrReg (void *Cpu)
 
TEMU_API void temu_ppcSetLrReg (void *Cpu, uint64_t Value)
 
TEMU_API uint64_t temu_ppcGetLrReg (void *Cpu)
 
TEMU_API void temu_cpuSetSpr (void *Cpu, unsigned RegId, uint64_t Value)
 
TEMU_API uint64_t temu_cpuGetSpr (void *Cpu, unsigned RegId)
 
TEMU_API void * temu_cpuGetMachine (void *Cpu)
 Get the Machine for a given CPU. More...
 
TEMU_API void temu_machineReset (void *Machine, int ResetType)
 Reset the Machine. More...
 
TEMU_API uint64_t temu_machineRun (void *Machine, uint64_t NanoSecs)
 Run the machine for a number of nanoseconds. More...
 
TEMU_API 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 periodically. Note that the callback will be called as soon as either a normal or the null 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 511 of file Cpu.h.

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

Definition at line 261 of file Cpu.h.

Function Documentation

TEMU_API uint32_t temu_armGetAPSR ( void *  Cpu)
TEMU_API unsigned temu_armGetExecMode ( void *  Cpu)
TEMU_API uint32_t temu_armGetFPEXC ( void *  Cpu)
TEMU_API uint32_t temu_armGetFPINST ( void *  Cpu,
int  Idx 
)
TEMU_API uint32_t temu_armGetFPSCR ( void *  Cpu)
TEMU_API void temu_armSetAPSR ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_armSetExecMode ( void *  Cpu,
unsigned  Mode 
)
TEMU_API void temu_armSetFPEXC ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_armSetFPINST ( void *  Cpu,
int  Idx,
uint32_t  Value 
)
TEMU_API void temu_armSetFPSCR ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_cpuDisableTraps ( void *  Cpu)

Disable traps on processor

Parameters
CpuCPU pointer
TEMU_API void temu_cpuEnableTraps ( void *  Cpu)

Enable traps on processor

Parameters
CpuCPU pointer
TEMU_API float temu_cpuGetFpr32 ( void *  Cpu,
unsigned  Reg 
)

Get a 32 bit floating point register

Parameters
CpuCPU pointer
RegFPU register number
Returns
Host float with the content of the FPU register
TEMU_API uint32_t temu_cpuGetFpr32Bits ( void *  Cpu,
unsigned  Reg 
)

Get a 32 bit floating point register

Parameters
CpuCPU pointer
RegFPU register number
Returns
Floating point register contents
TEMU_API double temu_cpuGetFpr64 ( void *  Cpu,
unsigned  Reg 
)

Get 64 bit floating point register as double

Parameters
CpuCPU pointer
RegFPU register number
Returns
FPU register value
TEMU_API uint64_t temu_cpuGetFpr64Bits ( void *  Cpu,
unsigned  Reg 
)

Get 64 bit floating point register contents

Parameters
CpuCPU pointer
RegFPU register number
Returns
FPU register value
TEMU_API 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.
TEMU_API void* temu_cpuGetMachine ( void *  Cpu)

Get the Machine for a given CPU.

Parameters
CpuPointer to the CPU object
Returns
Pointer to the machine object
TEMU_API 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
TEMU_API uint64_t temu_cpuGetReg ( void *  Cpu,
unsigned  Reg 
)

Gets the register in the processor

Parameters
CpuCPU pointer
RegRegister number
Returns
Register value
TEMU_API uint64_t temu_cpuGetSpr ( void *  Cpu,
unsigned  RegId 
)
TEMU_API void temu_cpuRaiseTrap ( void *  Cpu,
int  Trap,
unsigned  Flags 
)

Raise a trap The function simulates a trap being raised at the current PC.

Parameters
CpuProcessor pointer
TrapTrap ID. This is target dependent, for the SPARC this is the TT value of the trap.
Flagsset flag 1 to enable longjmp trap (this is useful in MMIO handlers to force a trap while a core is running). Set to 0 if called from outside the core or in e.g. an event handler.
TEMU_API 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.
TEMU_API 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.
TEMU_API void temu_cpuSetFpr32 ( void *  Cpu,
unsigned  Reg,
float  Value 
)

Set floating point register value

Parameters
CpuCPU pointer
RegFloating point register number
ValueFloating point value to set
TEMU_API void temu_cpuSetFpr32Bits ( void *  Cpu,
unsigned  Reg,
uint32_t  Value 
)

Set 32 bit floating point register value

Parameters
CpuCPU pointer
RegFloating point register number
ValueFloating point value to set
TEMU_API void temu_cpuSetFpr64 ( void *  Cpu,
unsigned  Reg,
double  Value 
)

Set FPU register value

Parameters
CpuCPU pointer
RegFPU register number
ValueValue to set to register
TEMU_API void temu_cpuSetFpr64Bits ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)

Set FPU register value

Parameters
CpuCPU pointer
RegFPU register number
ValueValue to set to register
TEMU_API 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.
TEMU_API void temu_cpuSetReg ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)

Set the register in the processor

Parameters
CpuCPU pointer
RegRegister number
ValueValue to write to register
TEMU_API void temu_cpuSetSpr ( void *  Cpu,
unsigned  RegId,
uint64_t  Value 
)
TEMU_API 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.
TEMU_API int temu_cpuTranslateAddress ( void *  Cpu,
uint64_t  Va,
uint32_t  flags,
uint64_t *  physAddressResult 
)

temu_cpuTranslateAddress Uses the MMU to translate the given virtual address Va to the physical address in the emulator

Parameters
Cputhe CPU object
Vathe virtual address to be translated
flagsflags for the translation (CPU specific)
physAddressResultthe result in a uint64_t pointer
Returns
error code. 0 on success, non-zero otherwise,
TEMU_API 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.
TEMU_API 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.
TEMU_API void temu_postCallback ( void *  Obj,
temu_SafeCb  Cb,
void *  Arg 
)
TEMU_API void temu_ppcClearAddressReservation ( void *  Cpu)
TEMU_API uint32_t temu_ppcGetCrReg ( void *  Cpu)
TEMU_API uint32_t temu_ppcGetCtrReg ( void *  Cpu)
TEMU_API uint32_t temu_ppcGetFpscrReg ( void *  Cpu)
TEMU_API uint64_t temu_ppcGetLrReg ( void *  Cpu)
TEMU_API uint64_t temu_ppcGetMsrReg ( void *  Cpu)
TEMU_API uint64_t temu_ppcGetReserveAddress ( void *  Cpu)
TEMU_API uint32_t temu_ppcGetXerReg ( void *  Cpu)
TEMU_API int temu_ppcIsReservationBitSet ( void *  Cpu)
TEMU_API void temu_ppcSetCrReg ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_ppcSetCtrReg ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_ppcSetFpscrReg ( void *  Cpu,
uint32_t  Value 
)
TEMU_API void temu_ppcSetLrReg ( void *  Cpu,
uint64_t  Value 
)
TEMU_API void temu_ppcSetMsrReg ( void *  Cpu,
uint64_t  Value 
)
TEMU_API void temu_ppcSetReserveAddress ( void *  Cpu,
uint64_t  reserveAddress 
)
TEMU_API void temu_ppcSetXerReg ( void *  Cpu,
uint32_t  Value 
)
TEMU_API uint64_t temu_sparcGetAsr ( void *  Cpu,
unsigned  Reg 
)

Get ASR register value

Parameters
CpuSPARC CPU pointer
RegASR register ID
Returns
ASR register value
TEMU_API uint32_t temu_sparcGetNPc ( void *  Cpu)

Get the nPC value

Parameters
CpuSPARC CPU pointer
Returns
nPC value
TEMU_API uint32_t temu_sparcGetPsr ( void *  Cpu)

Get the Processor State Register

Parameters
CpuSPARC CPU pointer
Returns
PSR value
TEMU_API uint32_t temu_sparcGetTbr ( void *  Cpu)

Get Trap Base Register value

Parameters
CpuSPARC CPU pointer
Returns
TBR value
TEMU_API uint32_t temu_sparcGetWim ( void *  Cpu)

Get window invalidation mask register

Parameters
CpuSPARC CPU pointer
Returns
WIM value
TEMU_API int temu_sparcGetWindowCount ( void *  Cpu)

Get how many register windows are supported by the CPU

Parameters
CpuSPARC CPU pointer
Returns
Number of register windows
TEMU_API uint32_t temu_sparcGetWindowedReg ( void *  Cpu,
int  Window,
unsigned  Reg 
)

Get a windowed SPARC register

Parameters
CpuSPARC CPU pointer
WindowWindow number (-1 for current window)
RegRegister number within window
Returns
Register value
TEMU_API uint64_t temu_sparcGetY ( void *  Cpu)

Get the Y register of the CPU,

Parameters
CpuSPARC CPU pointer
Returns
Current Y register value
TEMU_API void temu_sparcSetAsr ( void *  Cpu,
unsigned  Reg,
uint64_t  Value 
)

Set the ASR register

Parameters
CpuSPARC CPU pointer
RegASR register ID
ValueValue to write
TEMU_API void temu_sparcSetAsrReader ( void *  Cpu,
unsigned  Asr,
temu_SparcAsrHandler  Handler 
)

Install the handler to be called when an ASR is read

Parameters
CpuSPARC CPU pointer
AsrASR register ID
HandlerFunction to call.
TEMU_API void temu_sparcSetAsrWriter ( void *  Cpu,
unsigned  Asr,
temu_SparcAsrHandler  Handler 
)

Install the handler to be called when an ASR is written

Parameters
CpuSPARC CPU pointer
AsrASR register ID
HandlerFunction to call.
TEMU_API void temu_sparcSetNPc ( void *  Cpu,
uint32_t  Value 
)

Set the nPC value (next program counter)

NOTE: When you use the setPC function, the NPC is also updated to PC+4. Use this to explicitly set NPC.

Parameters
CpuSPARC CPU pointer
ValueValue to write to NPC
TEMU_API void temu_sparcSetPsr ( void *  Cpu,
uint32_t  Value 
)

Set the Processor State Register

Parameters
CpuSPARC CPU pointer
ValueValue to write
TEMU_API void temu_sparcSetTbr ( void *  Cpu,
uint32_t  Value 
)

Set the Trap Base Register

Parameters
CpuSPARC CPU pointer,
ValueValue for TBR register
TEMU_API void temu_sparcSetWim ( void *  Cpu,
uint32_t  Value 
)

Set window invalidation mask register

Parameters
CpuSPARC CPU pointer
Valuevalue to set in WIM
TEMU_API void temu_sparcSetWindowedReg ( void *  Cpu,
int  Window,
unsigned  Reg,
uint32_t  Value 
)

Set a windowed SPARC register

Parameters
CpuSPARC CPU pointer
WindowWindow number (-1 for current window)
RegRegister number within window
ValueRegister value
TEMU_API void temu_sparcSetY ( void *  Cpu,
uint64_t  Value 
)

Set the Y register of the CPU,

Parameters
CpuSPARC CPU pointer
ValueValue to write to the Y register