TEMU
4.4
The Terma Emulator
|
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) |
TEMU_API void | temu_cpuSetPc (void *Cpu, uint64_t Pc) |
TEMU_API uint64_t | temu_cpuGetPc (void *Cpu) |
TEMU_API void | temu_cpuReset (void *Cpu, int ResetType) |
TEMU_API uint64_t | temu_cpuRun (void *Cpu, uint64_t Cycles) |
TEMU_API uint64_t | temu_cpuStep (void *Cpu, uint64_t Steps) |
TEMU_API int | temu_cpuTranslateAddress (void *Cpu, uint64_t Va, uint32_t flags, uint64_t *physAddressResult) |
TEMU_API int | temu_cpuTranslateAddressWithRootPointer (void *cpu, uint64_t va, uint32_t flags, uint64_t *physAddressResult, uint64_t pageTableRoot) |
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) |
TEMU_API void | temu_machineReset (void *Machine, int ResetType) |
TEMU_API uint64_t | temu_machineRun (void *Machine, uint64_t NanoSecs) |
TEMU_API void | temu_postCallback (void *Obj, temu_SafeCb Cb, void *Arg) |
TEMU_API uint64_t | temu_cpuGetStat (void *Obj, int Stat) |
TEMU_API void | temu_cpuResetStat (void *Obj, int Stat) |
Wrappers functions for the CPU interfaces.
The functions declared in this file exists for convenience purposes. They will in general look up the relevant interface by name via a double map lookup.
The functions here provide an easy way invoke functions in the CpuIface without having to query for the interface and then calling the function.
If the emulator is integrated in a simulator, the recommended approach is to first construct the system, and then query relevant interfaces, caching them as needed. Note that system configurations should not normally change after the construction phase, so any cached object-interface pairs will be stable.
typedef void(* temu_SafeCb) (void *) |
typedef void(* temu_SparcAsrHandler) (void *Cpu, uint32_t Instr) |
TEMU_API uint32_t temu_armGetAPSR | ( | void * | Cpu | ) |
Get the ARM processor state register
Cpu | ARM CPU pointer |
TEMU_API unsigned temu_armGetExecMode | ( | void * | Cpu | ) |
Get the ARM execution mode
Cpu | ARM CPU pointer |
TEMU_API uint32_t temu_armGetFPEXC | ( | void * | Cpu | ) |
Get the ARM FPEXC register
Cpu | ARM CPU pointer |
TEMU_API uint32_t temu_armGetFPINST | ( | void * | Cpu, |
int | Idx | ||
) |
Get the ARM FPINST register
Cpu | ARM CPU pointer |
Idx | FPINST register number |
TEMU_API uint32_t temu_armGetFPSCR | ( | void * | Cpu | ) |
Get the ARM FPSCR register
Cpu | ARM CPU pointer |
TEMU_API void temu_armSetAPSR | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the ARM processor state register
Cpu | ARM CPU pointer |
Value | Value to set the APSR to |
TEMU_API void temu_armSetExecMode | ( | void * | Cpu, |
unsigned | Mode | ||
) |
Set the ARM execution mode
Cpu | ARM CPU pointer |
Mode | Execution mode |
TEMU_API void temu_armSetFPEXC | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the ARM FPEXC register
Cpu | ARM CPU pointer |
Value | FPEXC value |
TEMU_API void temu_armSetFPINST | ( | void * | Cpu, |
int | Idx, | ||
uint32_t | Value | ||
) |
Set the ARM FPINST register
Cpu | ARM CPU pointer |
Idx | FPINST register number |
Value | FPINST value |
TEMU_API void temu_armSetFPSCR | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the ARM FPSCR register
Cpu | ARM CPU pointer |
Value | FPSCR value |
TEMU_API void temu_cpuDisableTraps | ( | void * | Cpu | ) |
Disable traps on processor
Cpu | CPU pointer |
TEMU_API void temu_cpuEnableTraps | ( | void * | Cpu | ) |
Enable traps on processor
Cpu | CPU pointer |
TEMU_API float temu_cpuGetFpr32 | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Get a 32 bit floating point register
Cpu | CPU pointer |
Reg | FPU register number |
TEMU_API uint32_t temu_cpuGetFpr32Bits | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Get a 32 bit floating point register
Cpu | CPU pointer |
Reg | FPU register number |
TEMU_API double temu_cpuGetFpr64 | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Get 64 bit floating point register as double
Cpu | CPU pointer |
Reg | FPU register number |
TEMU_API uint64_t temu_cpuGetFpr64Bits | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Get 64 bit floating point register contents
Cpu | CPU pointer |
Reg | FPU register number |
TEMU_API uint64_t temu_cpuGetFreq | ( | void * | Cpu | ) |
Get the clock frequency for the CPU
Cpu | The CPU object |
TEMU_API void* temu_cpuGetMachine | ( | void * | Cpu | ) |
Get the Machine for a given CPU
Cpu | Pointer to the CPU object |
TEMU_API uint64_t temu_cpuGetPc | ( | void * | Cpu | ) |
Get the program counter
The program counter will be returned.
Cpu | The CPU object |
TEMU_API uint64_t temu_cpuGetReg | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Gets the register in the processor
Cpu | CPU pointer |
Reg | Register number |
TEMU_API uint64_t temu_cpuGetSpr | ( | void * | Cpu, |
unsigned | RegId | ||
) |
Get the PowerPC SPR register
Cpu | Processor pointer |
RegId | SPR register number |
RegId
. TEMU_API uint64_t temu_cpuGetStat | ( | void * | Obj, |
int | Stat | ||
) |
Get processor statistics
Obj | Processor pointer |
Stat | Statistics ID |
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.
Cpu | Processor pointer |
Trap | Trap ID. This is target dependent, for the SPARC this is the TT value of the trap. |
Flags | set 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.
Cpu | The CPU object |
ResetType | The type of reset, by convention 0 means cold reset, and 1 indicates a warm reset. |
TEMU_API void temu_cpuResetStat | ( | void * | Obj, |
int | Stat | ||
) |
Clear processor statistics
Obj | Processor pointer |
Stat | Statistics ID |
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.
Cpu | The CPU object |
Cycles | The number of cycles to run the processor for. |
TEMU_API void temu_cpuSetFpr32 | ( | void * | Cpu, |
unsigned | Reg, | ||
float | Value | ||
) |
Set floating point register value
Cpu | CPU pointer |
Reg | Floating point register number |
Value | Floating point value to set |
TEMU_API void temu_cpuSetFpr32Bits | ( | void * | Cpu, |
unsigned | Reg, | ||
uint32_t | Value | ||
) |
Set 32 bit floating point register value
Cpu | CPU pointer |
Reg | Floating point register number |
Value | Floating point value to set |
TEMU_API void temu_cpuSetFpr64 | ( | void * | Cpu, |
unsigned | Reg, | ||
double | Value | ||
) |
Set FPU register value
Cpu | CPU pointer |
Reg | FPU register number |
Value | Value to set to register |
TEMU_API void temu_cpuSetFpr64Bits | ( | void * | Cpu, |
unsigned | Reg, | ||
uint64_t | Value | ||
) |
Set FPU register value
Cpu | CPU pointer |
Reg | FPU register number |
Value | Value 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.
Cpu | The CPU object |
Pc | The program counter. |
TEMU_API void temu_cpuSetReg | ( | void * | Cpu, |
unsigned | Reg, | ||
uint64_t | Value | ||
) |
Set the register in the processor
Cpu | CPU pointer |
Reg | Register number |
Value | Value to write to register |
TEMU_API void temu_cpuSetSpr | ( | void * | Cpu, |
unsigned | RegId, | ||
uint64_t | Value | ||
) |
Set the PowerPC SPR register
Cpu | Processor pointer |
RegId | SPR register number |
Value | New SPR 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.
Cpu | The CPU object |
Steps | The number of steps to run the processor for. |
TEMU_API int temu_cpuTranslateAddress | ( | void * | Cpu, |
uint64_t | Va, | ||
uint32_t | flags, | ||
uint64_t * | physAddressResult | ||
) |
Uses the MMU to translate the given virtual address Va to the physical address in the emulator
Cpu | the CPU object |
Va | the virtual address to be translated |
flags | flags for the translation (CPU specific) |
physAddressResult | the result in a uint64_t pointer |
TEMU_API int temu_cpuTranslateAddressWithRootPointer | ( | void * | cpu, |
uint64_t | va, | ||
uint32_t | flags, | ||
uint64_t * | physAddressResult, | ||
uint64_t | pageTableRoot | ||
) |
Uses the an explicit page table pointer to translate a virtual address to physical address.
The routine is dependent on the processor having hardware managed page tables. Hence this works e.g. for SPARC and ARM processors, but not for PowerPC.
cpu | the CPU object |
va | the virtual address to be translated |
flags | flags for the translation (CPU specific) |
physAddressResult | the result in a uint64_t pointer |
pageTableRoot | The page table to use for the translation |
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.
Machine | The Machine object |
ResetType | The 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.
Machine | The machine object |
NanoSecs | The number of nanosecs to run each processor for. |
TEMU_API void temu_postCallback | ( | void * | Obj, |
temu_SafeCb | Cb, | ||
void * | Arg | ||
) |
Post a callback in a time source
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:
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:
Obj | Time source |
Cb | Callback |
Arg | Argument passed to callback |
TEMU_API void temu_ppcClearAddressReservation | ( | void * | Cpu | ) |
Clear the PowerPC reserve address used by lwarx
and stwcx
Cpu | Processor pointer |
TEMU_API uint32_t temu_ppcGetCrReg | ( | void * | Cpu | ) |
Get the PowerPC CR register
Cpu | Processor pointer |
TEMU_API uint32_t temu_ppcGetCtrReg | ( | void * | Cpu | ) |
Get the PowerPC CTR register
Cpu | Processor pointer |
TEMU_API uint32_t temu_ppcGetFpscrReg | ( | void * | Cpu | ) |
Get the PowerPC FPSCR register
Cpu | Processor pointer |
TEMU_API uint64_t temu_ppcGetLrReg | ( | void * | Cpu | ) |
Get the PowerPC LR register
Cpu | Processor pointer |
TEMU_API uint64_t temu_ppcGetMsrReg | ( | void * | Cpu | ) |
Get the PowerPC MSR register
Cpu | Processor pointer |
TEMU_API uint64_t temu_ppcGetReserveAddress | ( | void * | Cpu | ) |
Get the PowerPC reserve address used by lwarx
and stwcx
Cpu | Processor pointer |
TEMU_API uint32_t temu_ppcGetXerReg | ( | void * | Cpu | ) |
Get the PowerPC XER register
Cpu | Processor pointer |
TEMU_API int temu_ppcIsReservationBitSet | ( | void * | Cpu | ) |
Check if PowerPC reserve address is set lwarx
and stwcx
Cpu | Processor pointer |
TEMU_API void temu_ppcSetCrReg | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the PowerPC CR register
Cpu | Processor pointer |
Value | New CR value |
TEMU_API void temu_ppcSetCtrReg | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the PowerPC CTR register
Cpu | Processor pointer |
Value | New CTR value |
TEMU_API void temu_ppcSetFpscrReg | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the PowerPC FPSCR register
Cpu | Processor pointer |
Value | New FPSCR value |
TEMU_API void temu_ppcSetLrReg | ( | void * | Cpu, |
uint64_t | Value | ||
) |
Set the PowerPC LR register
Cpu | Processor pointer |
Value | New LR value |
TEMU_API void temu_ppcSetMsrReg | ( | void * | Cpu, |
uint64_t | Value | ||
) |
Set the PowerPC MSR register
Cpu | Processor pointer |
Value | New MSR value |
TEMU_API void temu_ppcSetReserveAddress | ( | void * | Cpu, |
uint64_t | reserveAddress | ||
) |
Set the PowerPC reserve address used by lwarx
and stwcx
Cpu | Processor pointer |
reserveAddress | New reserved address value |
TEMU_API void temu_ppcSetXerReg | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the PowerPC XER register
Cpu | Processor pointer |
Value | New XER value |
TEMU_API uint64_t temu_sparcGetAsr | ( | void * | Cpu, |
unsigned | Reg | ||
) |
Get ASR register value
Cpu | SPARC CPU pointer |
Reg | ASR register ID |
TEMU_API uint32_t temu_sparcGetNPc | ( | void * | Cpu | ) |
Get the nPC value
Cpu | SPARC CPU pointer |
TEMU_API uint32_t temu_sparcGetPsr | ( | void * | Cpu | ) |
Get the Processor State Register
Cpu | SPARC CPU pointer |
TEMU_API uint32_t temu_sparcGetTbr | ( | void * | Cpu | ) |
Get Trap Base Register value
Cpu | SPARC CPU pointer |
TEMU_API uint32_t temu_sparcGetWim | ( | void * | Cpu | ) |
Get window invalidation mask register
Cpu | SPARC CPU pointer |
TEMU_API int temu_sparcGetWindowCount | ( | void * | Cpu | ) |
Get how many register windows are supported by the CPU
Cpu | SPARC CPU pointer |
TEMU_API uint32_t temu_sparcGetWindowedReg | ( | void * | Cpu, |
int | Window, | ||
unsigned | Reg | ||
) |
Get a windowed SPARC register
Cpu | SPARC CPU pointer |
Window | Window number (-1 for current window) |
Reg | Register number within window |
TEMU_API uint64_t temu_sparcGetY | ( | void * | Cpu | ) |
Get the Y register of the CPU,
Cpu | SPARC CPU pointer |
TEMU_API void temu_sparcSetAsr | ( | void * | Cpu, |
unsigned | Reg, | ||
uint64_t | Value | ||
) |
Set the ASR register
Cpu | SPARC CPU pointer |
Reg | ASR register ID |
Value | Value 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
Cpu | SPARC CPU pointer |
Asr | ASR register ID |
Handler | Function 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
Cpu | SPARC CPU pointer |
Asr | ASR register ID |
Handler | Function 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.
Cpu | SPARC CPU pointer |
Value | Value to write to NPC |
TEMU_API void temu_sparcSetPsr | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the Processor State Register
Cpu | SPARC CPU pointer |
Value | Value to write |
TEMU_API void temu_sparcSetTbr | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set the Trap Base Register
Cpu | SPARC CPU pointer, |
Value | Value for TBR register |
TEMU_API void temu_sparcSetWim | ( | void * | Cpu, |
uint32_t | Value | ||
) |
Set window invalidation mask register
Cpu | SPARC CPU pointer |
Value | value to set in WIM |
TEMU_API void temu_sparcSetWindowedReg | ( | void * | Cpu, |
int | Window, | ||
unsigned | Reg, | ||
uint32_t | Value | ||
) |
Set a windowed SPARC register
Cpu | SPARC CPU pointer |
Window | Window number (-1 for current window) |
Reg | Register number within window |
Value | Register value |
TEMU_API void temu_sparcSetY | ( | void * | Cpu, |
uint64_t | Value | ||
) |
Set the Y register of the CPU,
Cpu | SPARC CPU pointer |
Value | Value to write to the Y register |