T32 Simulator: Basic Instruction set sim for ARMM3
The T32 can simulate bare instruction sets without periphery. For the Cortex-M3 we have complete NVIC model including Systick Timer. Currently a simple CiAO can run on the simulator. TODO: - Let memlogger log all memory accesses. - Interact with FailT32 for a complete simulation/FI
This commit is contained in:
532
debuggers/t32/sim/include/simul.c
Normal file
532
debuggers/t32/sim/include/simul.c
Normal file
@ -0,0 +1,532 @@
|
||||
|
||||
#include "simul.h"
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Model entry
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
int SIMULAPI SIMUL_Interface(simulProcessor processor, simulCallbackStruct * cbs)
|
||||
{
|
||||
cbs->x.init.version = SIMUL_VERSION;
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
cbs->x.init.argpword = cbs->x.init.argpword64;
|
||||
cbs->x.init.argpaddress = cbs->x.init.argpaddress64;
|
||||
#else
|
||||
cbs->x.init.argpword = cbs->x.init.argpword32;
|
||||
cbs->x.init.argpaddress = cbs->x.init.argpaddress32;
|
||||
#endif
|
||||
return SIMUL_Init(processor, cbs);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Generic configuration functions
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
void SIMULAPI SIMUL_Printf(simulProcessor processor, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
(*((simulProcInfo *) processor)->printf) (processor, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_Warning(simulProcessor processor, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
(*((simulProcInfo *) processor)->warning) (processor, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_Stop(simulProcessor processor)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->stop) (processor);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_Update(simulProcessor processor, int flags)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->update) (processor, flags);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_Alloc(simulProcessor processor, int size)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->alloc)(processor, size);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_Free(simulProcessor processor, void * ptr)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->free)(processor, ptr);
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_GetEndianess(simulProcessor processor)
|
||||
{
|
||||
return ((simulProcInfo *) processor)->endianess;
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterCommandCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerCommandCallback) (processor, func, private, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterResetCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerResetCallback)(processor, func, private);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterExitCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerExitCallback)(processor, func, private);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterGoCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerGoCallback)(processor, func, private);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterBreakCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerBreakCallback)(processor, func, private);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Clocks and Timers
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
void SIMULAPI SIMUL_GetClockFrequency(simulProcessor processor, int id, simulWord64 * pfrequency)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->getClockFrequency)(processor, id, pfrequency);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_SetClockFrequency(simulProcessor processor, int id, simulWord64 * pfrequency)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->setClockFrequency)(processor, id, pfrequency);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_GetClockCycle(simulProcessor processor, int id, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->getClockCycle)(processor, id, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_SetClockCycle(simulProcessor processor, int id, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->setClockCycle)(processor, id, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_GetTime(simulProcessor processor, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->getTime)(processor, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_GetClock(simulProcessor processor, int timerid, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->getClock) (processor, timerid, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_Stall(simulProcessor processor, int mode, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->stall) (processor, mode, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_StartTimer(simulProcessor processor, void * timerid, int mode, simulTime * ptime)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->startTimer)(processor, timerid, mode, ptime);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_StopTimer(simulProcessor processor, void * timerid)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->stopTimer)(processor, timerid);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_StopAllTimer(simulProcessor processor)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->stopTimer) (processor);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterTimerCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerTimerCallback)(processor, func, private);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Buses and Memories
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
int SIMULAPI SIMUL_ReadMemory(simulProcessor processor, int bustype, simulWord * paddress, int width, int cycletype, simulWord * pdata)
|
||||
{
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
return (*((simulProcInfo *) processor)->readMemory64) (processor, bustype, paddress, width, cycletype, pdata);
|
||||
#else
|
||||
return (*((simulProcInfo *) processor)->readMemory32) (processor, bustype, paddress, width, cycletype, pdata);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_WriteMemory(simulProcessor processor, int bustype, simulWord * paddress, int width, int cycletype, simulWord * pdata)
|
||||
{
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
return (*((simulProcInfo *) processor)->writeMemory64) (processor, bustype, paddress, width, cycletype, pdata);
|
||||
#else
|
||||
return (*((simulProcInfo *) processor)->writeMemory32) (processor, bustype, paddress, width, cycletype, pdata);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterBusWriteCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private, int bustype, simulWord * paddressFrom, simulWord * paddressTo)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerBusWriteCallback)(processor, func, private, bustype, paddressFrom, paddressTo, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterBusReadCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private, int bustype, simulWord * paddressFrom, simulWord * paddressTo)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerBusReadCallback)(processor, func, private, bustype, paddressFrom, paddressTo, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_RelocateBusCallback(simulProcessor processor, void * callbackid, int bustype, simulWord * paddressFrom, simulWord * paddressTo)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->relocateBusCallback)(processor, callbackid, bustype, paddressFrom, paddressTo, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_InsertWord(simulProcessor processor, simulWord * ptarget , int wordwidth, simulWord * paddress, int width, simulWord * pdata)
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (width >= wordwidth) {
|
||||
*ptarget = *pdata;
|
||||
} else if (width == 8) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 8 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*ptarget = (*ptarget & ~(0xff << offset)) | ((*pdata & 0xff) << offset);
|
||||
} else if (width == 16) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 16 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*ptarget = (*ptarget & ~(0xffff << offset)) | ((*pdata & 0xffff) << offset);
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
} else if (width == 32) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 32 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*ptarget = (*ptarget & ~(0xffffffff << offset)) | ((*pdata & 0xffffffff) << offset);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_ExtractWord(simulProcessor processor, simulWord * psource, int wordwidth, simulWord * paddress, int width, simulWord * pdata)
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (width >= wordwidth) {
|
||||
*pdata = *psource;
|
||||
} else if (width == 8) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 8 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*pdata = (*psource >> offset) & 0xff;
|
||||
} else if (width == 16) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 16 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*pdata = (*psource >> offset) & 0xffff;
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
} else if (width == 32) {
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
offset = wordwidth - 32 - ((*paddress << 3) & (wordwidth - 1));
|
||||
} else {
|
||||
offset = (*paddress << 3) & (wordwidth - 1);
|
||||
}
|
||||
*pdata = (*psource >> offset) & 0xffffffff;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_SaveWord(simulProcessor processor, void * ptarget, int width, simulWord * pdata)
|
||||
{
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
switch (width>>3) {
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
case 8:
|
||||
((unsigned char *) ptarget)[0] = *pdata >> 56;
|
||||
((unsigned char *) ptarget)[1] = *pdata >> 48;
|
||||
((unsigned char *) ptarget)[2] = *pdata >> 40;
|
||||
((unsigned char *) ptarget)[3] = *pdata >> 32;
|
||||
((unsigned char *) ptarget)[4] = *pdata >> 24;
|
||||
((unsigned char *) ptarget)[5] = *pdata >> 16;
|
||||
((unsigned char *) ptarget)[6] = *pdata >> 8;
|
||||
((unsigned char *) ptarget)[7] = *pdata;
|
||||
break;
|
||||
#endif
|
||||
case 4:
|
||||
((unsigned char *) ptarget)[0] = *pdata >> 24;
|
||||
((unsigned char *) ptarget)[1] = *pdata >> 16;
|
||||
((unsigned char *) ptarget)[2] = *pdata >> 8;
|
||||
((unsigned char *) ptarget)[3] = *pdata;
|
||||
break;
|
||||
case 2:
|
||||
((unsigned char *) ptarget)[0] = *pdata >> 8;
|
||||
((unsigned char *) ptarget)[1] = *pdata;
|
||||
break;
|
||||
default:
|
||||
((unsigned char *) ptarget)[0] = *pdata;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (width>>3) {
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
case 8:
|
||||
((unsigned char *) ptarget)[7] = *pdata >> 56;
|
||||
((unsigned char *) ptarget)[6] = *pdata >> 48;
|
||||
((unsigned char *) ptarget)[5] = *pdata >> 40;
|
||||
((unsigned char *) ptarget)[4] = *pdata >> 32;
|
||||
#endif
|
||||
case 4:
|
||||
((unsigned char *) ptarget)[3] = *pdata >> 24;
|
||||
((unsigned char *) ptarget)[2] = *pdata >> 16;
|
||||
case 2:
|
||||
((unsigned char *) ptarget)[1] = *pdata >> 8;
|
||||
default:
|
||||
((unsigned char *) ptarget)[0] = *pdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_LoadWord(simulProcessor processor, void * psource, int width, simulWord * pdata)
|
||||
{
|
||||
if (((simulProcInfo *) processor)->endianess) {
|
||||
switch (width>>3) {
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
case 8:
|
||||
{
|
||||
simulWord low, high;
|
||||
low = (((unsigned char *) psource)[7]) | (((unsigned char *) psource)[6] << 8)
|
||||
| (((unsigned char *) psource)[5] << 16) | (((unsigned char *) psource)[4] << 24);
|
||||
high = (((unsigned char *) psource)[3]) | (((unsigned char *) psource)[2] << 8)
|
||||
| (((unsigned char *) psource)[1] << 16) | (((unsigned char *) psource)[0] << 24);
|
||||
*pdata = low | (high << 32);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 4:
|
||||
*pdata = (((unsigned char *) psource)[3]) | (((unsigned char *) psource)[2] << 8)
|
||||
| (((unsigned char *) psource)[1] << 16) | (((unsigned char *) psource)[0] << 24);
|
||||
break;
|
||||
case 2:
|
||||
*pdata = (((unsigned char *) psource)[1]) | (((unsigned char *) psource)[0] << 8);
|
||||
break;
|
||||
default:
|
||||
*pdata = ((unsigned char *) psource)[0];
|
||||
}
|
||||
} else {
|
||||
switch (width>>3) {
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
case 8:
|
||||
{
|
||||
simulWord low, high;
|
||||
low = (((unsigned char *) psource)[0]) | (((unsigned char *) psource)[1] << 8)
|
||||
| (((unsigned char *) psource)[2] << 16) | (((unsigned char *) psource)[3] << 24);
|
||||
high = (((unsigned char *) psource)[4]) | (((unsigned char *) psource)[5] << 8)
|
||||
| (((unsigned char *) psource)[6] << 16) | (((unsigned char *) psource)[7] << 24);
|
||||
*pdata = low | (high << 32);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case 4:
|
||||
*pdata = (((unsigned char *) psource)[0]) | (((unsigned char *) psource)[1] << 8)
|
||||
| (((unsigned char *) psource)[2] << 16) | (((unsigned char *) psource)[3] << 24);
|
||||
break;
|
||||
case 2:
|
||||
*pdata = (((unsigned char *) psource)[0]) | (((unsigned char *) psource)[1] << 8);
|
||||
break;
|
||||
default:
|
||||
*pdata = ((unsigned char *) psource)[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Ports
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
int SIMULAPI SIMUL_GetPort(simulProcessor processor, int offset, int width, simulWord * pdata)
|
||||
{
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
return (*((simulProcInfo *) processor)->getPort64) (processor, offset, width, pdata);
|
||||
#else
|
||||
return (*((simulProcInfo *) processor)->getPort32) (processor, offset, width, pdata);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_SetPort(simulProcessor processor, int offset, int width, simulWord * pdata)
|
||||
{
|
||||
#if SIMUL_ARCHITECTURE_WIDTH == 8
|
||||
return (*((simulProcInfo *) processor)->setPort64) (processor, offset, width, pdata);
|
||||
#else
|
||||
return (*((simulProcInfo *) processor)->setPort32) (processor, offset, width, pdata);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void * SIMULAPI SIMUL_RegisterPortChangeCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private, int offset, int width)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerPortChangeCallback)(processor, func, private, offset, width, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Shared Resources
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
int SIMULAPI SIMUL_CreateSharedResource(simulProcessor processor, int size)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->createSharedResource) (processor, size);
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_ReadSharedResource(simulProcessor processor, int offset, int len, void * pdata)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->readSharedResource) (processor, offset, len, pdata);
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_WriteSharedResource(simulProcessor processor, int offset, int len, void * pdata)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->writeSharedResource) (processor, offset, len, pdata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
File I/O
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
void * SIMULAPI SIMUL_OpenFile(simulProcessor processor, const char * filename, int mode)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->openFile) (processor, filename, mode);
|
||||
}
|
||||
|
||||
|
||||
void SIMULAPI SIMUL_CloseFile(simulProcessor processor, void * file)
|
||||
{
|
||||
(*((simulProcInfo *) processor)->closeFile) (processor, file);
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_ReadFile(simulProcessor processor, void * file, void * pdata, int length)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->readFile) (processor, file, pdata, length);
|
||||
}
|
||||
|
||||
int SIMULAPI SIMUL_WriteFile(simulProcessor processor, void * file, void * pdata, int length)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->writeFile) (processor, file, pdata, length);
|
||||
}
|
||||
|
||||
|
||||
int SIMULAPI SIMUL_ReadlineFile(simulProcessor processor, void * file, void * pdata, int length)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->readlineFile) (processor, file, pdata, length);
|
||||
}
|
||||
|
||||
int SIMULAPI SIMUL_WritelineFile(simulProcessor processor, void * file, void * pdata)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->writelineFile) (processor, file, pdata);
|
||||
}
|
||||
|
||||
|
||||
long SIMULAPI SIMUL_SeekFile(simulProcessor processor, void * file, long pos, int mode)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->seekFile) (processor, file, pos, mode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Terminal I/O
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
int SIMULAPI SIMUL_StateTerminal(simulProcessor processor, int id)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->stateTerminal) (processor, id);
|
||||
}
|
||||
|
||||
int SIMULAPI SIMUL_ReadTerminal(simulProcessor processor, int id)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->readTerminal) (processor, id);
|
||||
}
|
||||
|
||||
int SIMULAPI SIMUL_WriteTerminal(simulProcessor processor, int id, int ch)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->writeTerminal) (processor, id, ch);
|
||||
}
|
||||
|
||||
void * SIMUL_RegisterTerminalCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr private, int id)
|
||||
{
|
||||
return (*((simulProcInfo *) processor)->registerTerminalCallback) (processor, func, private, id, SIMUL_ARCHITECTURE_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
553
debuggers/t32/sim/include/simul.h
Normal file
553
debuggers/t32/sim/include/simul.h
Normal file
@ -0,0 +1,553 @@
|
||||
#ifndef __SIMUL_H
|
||||
#define __SIMUL_H
|
||||
/**************************************************************************
|
||||
|
||||
Basic types and includes
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
typedef __int64 simulTime;
|
||||
typedef unsigned __int64 simulWord64;
|
||||
|
||||
#define SIMULAPI __cdecl
|
||||
|
||||
#else
|
||||
|
||||
#include "stdarg.h"
|
||||
|
||||
#ifdef NSC32000
|
||||
typedef QUAD simulTime;
|
||||
typedef QUAD simulWord64;
|
||||
#else
|
||||
typedef long long simulTime;
|
||||
typedef unsigned long long simulWord64;
|
||||
#endif
|
||||
|
||||
#define SIMULAPI
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
typedef unsigned int simulWord32;
|
||||
|
||||
#define SIMUL_VERSION 1
|
||||
|
||||
#ifdef SIMUL_ARCHITECTURE_64BIT
|
||||
#define SIMUL_ARCHITECTURE_WIDTH 8
|
||||
typedef simulWord64 simulWord;
|
||||
#else
|
||||
#define SIMUL_ARCHITECTURE_WIDTH 4
|
||||
typedef simulWord32 simulWord;
|
||||
#endif
|
||||
|
||||
typedef void * simulProcessor;
|
||||
typedef void * simulPtr;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Internal callback structure (DO NOT ACCESS THIS STRUCTURE)
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int endianess;
|
||||
int addresswidth;
|
||||
int datawidth;
|
||||
int processortype;
|
||||
int id;
|
||||
int resvd1;
|
||||
int resvd2;
|
||||
int resvd3;
|
||||
|
||||
void (SIMULAPI *printf)();
|
||||
void (SIMULAPI *warning)();
|
||||
void (SIMULAPI *stop)();
|
||||
void (SIMULAPI *update)();
|
||||
void * (SIMULAPI *alloc)();
|
||||
void (SIMULAPI *free)();
|
||||
void * (SIMULAPI *registerCommandCallback)();
|
||||
void * (SIMULAPI *registerResetCallback)();
|
||||
void * (SIMULAPI *registerExitCallback)();
|
||||
|
||||
void (SIMULAPI *getClockFrequency)();
|
||||
void (SIMULAPI *setClockFrequency)();
|
||||
void (SIMULAPI *getClockCycle)();
|
||||
void (SIMULAPI *setClockCycle)();
|
||||
void (SIMULAPI *getTime)();
|
||||
void (SIMULAPI *getClock)();
|
||||
void (SIMULAPI *stall)();
|
||||
void (SIMULAPI *startTimer)();
|
||||
void (SIMULAPI *stopTimer)();
|
||||
void (SIMULAPI *stopAllTimer)();
|
||||
void * (SIMULAPI *registerTimerCallback)();
|
||||
|
||||
int (SIMULAPI *readMemory32)();
|
||||
int (SIMULAPI *readMemory64)();
|
||||
int (SIMULAPI *writeMemory32)();
|
||||
int (SIMULAPI *writeMemory64)();
|
||||
void * (SIMULAPI *registerBusReadCallback)();
|
||||
void * (SIMULAPI *registerBusWriteCallback)();
|
||||
void (SIMULAPI *relocateBusCallback)();
|
||||
|
||||
int (SIMULAPI *getPort32)();
|
||||
int (SIMULAPI *getPort64)();
|
||||
int (SIMULAPI *setPort32)();
|
||||
int (SIMULAPI *setPort64)();
|
||||
void * (SIMULAPI *registerPortChangeCallback)();
|
||||
|
||||
int (SIMULAPI *createSharedResource)();
|
||||
int (SIMULAPI *readSharedResource)();
|
||||
int (SIMULAPI *writeSharedResource)();
|
||||
|
||||
void * (SIMULAPI *openFile)();
|
||||
void (SIMULAPI *closeFile)();
|
||||
int (SIMULAPI *readFile)();
|
||||
int (SIMULAPI *writeFile)();
|
||||
int (SIMULAPI *readlineFile)();
|
||||
int (SIMULAPI *writelineFile)();
|
||||
long (SIMULAPI *seekFile)();
|
||||
|
||||
int (SIMULAPI *readTerminal)();
|
||||
int (SIMULAPI *writeTerminal)();
|
||||
int (SIMULAPI *stateTerminal)();
|
||||
void * (SIMULAPI *registerTerminalCallback)();
|
||||
|
||||
void * (SIMULAPI *registerGoCallback)();
|
||||
void * (SIMULAPI *registerBreakCallback)();
|
||||
}
|
||||
simulProcInfo;
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Callback structure
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#define SIMUL_CALLBACK_INIT 0x0000
|
||||
#define SIMUL_CALLBACK_BUSREAD 0x0001
|
||||
#define SIMUL_CALLBACK_BUSWRITE 0x0002
|
||||
#define SIMUL_CALLBACK_PORTCHANGE 0x0004
|
||||
#define SIMUL_CALLBACK_TIMER 0x0010
|
||||
#define SIMUL_CALLBACK_EXIT 0x0020
|
||||
#define SIMUL_CALLBACK_RESET 0x0040
|
||||
#define SIMUL_CALLBACK_TERMINAL 0x0080
|
||||
#define SIMUL_CALLBACK_COMMAND 0x0100
|
||||
#define SIMUL_CALLBACK_GO 0x0200
|
||||
#define SIMUL_CALLBACK_BREAK 0x0400
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int version;
|
||||
char * modelname;
|
||||
char * commandline;
|
||||
int argc;
|
||||
char ** argp;
|
||||
int * argpint;
|
||||
simulWord * argpword;
|
||||
simulWord32 * argpword32;
|
||||
simulWord64 * argpword64;
|
||||
int * argpport;
|
||||
int * argpbustype;
|
||||
simulWord * argpaddress;
|
||||
simulWord32 * argpaddress32;
|
||||
simulWord64 * argpaddress64;
|
||||
simulTime * argptime;
|
||||
}
|
||||
simulParamCallbackStruct;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord address;
|
||||
simulWord data;
|
||||
int width;
|
||||
int cycletype;
|
||||
int clocks;
|
||||
}
|
||||
simulBusCallbackStruct;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord32 address;
|
||||
simulWord32 data;
|
||||
int width;
|
||||
int cycletype;
|
||||
int clocks;
|
||||
}
|
||||
simulBusCallbackStruct32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord64 address;
|
||||
simulWord64 data;
|
||||
int width;
|
||||
int cycletype;
|
||||
int clocks;
|
||||
}
|
||||
simulBusCallbackStruct64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord newdata;
|
||||
simulWord olddata;
|
||||
}
|
||||
simulPortCallbackStruct;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord32 newdata;
|
||||
simulWord32 olddata;
|
||||
}
|
||||
simulPortCallbackStruct32;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simulWord64 newdata;
|
||||
simulWord64 olddata;
|
||||
}
|
||||
simulPortCallbackStruct64;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int data;
|
||||
}
|
||||
simulTerminalCallbackStruct;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
simulTime time;
|
||||
union {
|
||||
simulParamCallbackStruct init;
|
||||
simulParamCallbackStruct command;
|
||||
simulBusCallbackStruct bus;
|
||||
simulBusCallbackStruct32 bus32;
|
||||
simulBusCallbackStruct64 bus64;
|
||||
simulPortCallbackStruct port;
|
||||
simulPortCallbackStruct32 port32;
|
||||
simulPortCallbackStruct64 port64;
|
||||
simulTerminalCallbackStruct terminal;
|
||||
} x;
|
||||
}
|
||||
simulCallbackStruct;
|
||||
|
||||
|
||||
typedef int (SIMULAPI * simulCallbackFunctionPtr)(simulProcessor processor, simulCallbackStruct *, simulPtr priv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Model entry definition
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#define SIMUL_INIT_OK 1
|
||||
#define SIMUL_INIT_FAIL -1
|
||||
|
||||
extern int SIMULAPI SIMUL_Init(simulProcessor processor, simulCallbackStruct * cbs);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Generic configuration functions
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
extern void SIMULAPI SIMUL_Printf(simulProcessor processor, const char *format, ...);
|
||||
|
||||
extern void SIMULAPI SIMUL_Warning(simulProcessor processor, const char *format, ...);
|
||||
|
||||
extern void SIMULAPI SIMUL_Stop(simulProcessor processor);
|
||||
|
||||
extern void SIMULAPI SIMUL_Update(simulProcessor processor, int flags);
|
||||
|
||||
extern void * SIMULAPI SIMUL_Alloc(simulProcessor processor, int size);
|
||||
|
||||
extern void SIMULAPI SIMUL_Free(simulProcessor processor, void * ptr);
|
||||
|
||||
|
||||
#define SIMUL_ENDIANESS_LITTLE 0
|
||||
#define SIMUL_ENDIANESS_BIG 1
|
||||
|
||||
extern int SIMULAPI SIMUL_GetEndianess(simulProcessor processor);
|
||||
|
||||
|
||||
#define SIMUL_COMMAND_OK 1
|
||||
#define SIMUL_COMMAND_FAIL -1
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterCommandCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
#define SIMUL_RESET_OK 1
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterResetCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
#define SIMUL_EXIT_OK 1
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterExitCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
#define SIMUL_GO_OK 1
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterGoCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
#define SIMUL_BREAK_OK 1
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterBreakCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Clocks and Timers
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#define SIMUL_TIMER_OK 1
|
||||
|
||||
|
||||
#define SIMUL_CLOCK_CORE 0
|
||||
#define SIMUL_CLOCK_BUS 1
|
||||
#define SIMUL_CLOCK_POWERPC_TIMEBASE 2
|
||||
|
||||
|
||||
extern void SIMULAPI SIMUL_GetClockFrequency(simulProcessor processor, int clockid, simulWord64 * pfrequency);
|
||||
|
||||
extern void SIMULAPI SIMUL_SetClockFrequency(simulProcessor processor, int clockid, simulWord64 * pfrequency);
|
||||
|
||||
extern void SIMULAPI SIMUL_GetClockCycle(simulProcessor processor, int clockid, simulTime * ptime);
|
||||
|
||||
extern void SIMULAPI SIMUL_SetClockCycle(simulProcessor processor, int clockid, simulTime * ptime);
|
||||
|
||||
extern void SIMULAPI SIMUL_GetTime(simulProcessor processor, simulTime * ptime);
|
||||
|
||||
extern void SIMULAPI SIMUL_GetClock(simulProcessor processor, int clockid, simulTime * ptime);
|
||||
|
||||
#define SIMUL_STALL_ABS 0x000
|
||||
#define SIMUL_STALL_REL 0x100
|
||||
#define SIMUL_STALL_CLOCKS 0x400
|
||||
|
||||
extern void SIMULAPI SIMUL_Stall(simulProcessor processor, int mode, simulTime * ptime);
|
||||
|
||||
|
||||
/* timer modes */
|
||||
|
||||
#define SIMUL_TIMER_ABS 0x000
|
||||
#define SIMUL_TIMER_REL 0x100
|
||||
#define SIMUL_TIMER_SINGLE 0x000
|
||||
#define SIMUL_TIMER_REPEAT 0x200
|
||||
#define SIMUL_TIMER_CLOCKS 0x400
|
||||
|
||||
|
||||
extern void SIMULAPI SIMUL_StartTimer(simulProcessor processor, void * timerid, int mode, simulTime * ptime);
|
||||
|
||||
extern void SIMULAPI SIMUL_StopTimer(simulProcessor processor, void * timerid);
|
||||
|
||||
extern void SIMULAPI SIMUL_StopAllTimer(simulProcessor processor);
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterTimerCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Buses and Memories
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
/* return values for bus callback functions */
|
||||
|
||||
#define SIMUL_MEMORY_CONTINUE 0
|
||||
#define SIMUL_MEMORY_OK 1
|
||||
#define SIMUL_MEMORY_FAIL -1
|
||||
|
||||
/* cycle types */
|
||||
|
||||
#define SIMUL_MEMORY_HIDDEN 0x00
|
||||
#define SIMUL_MEMORY_FETCH 0x02
|
||||
#define SIMUL_MEMORY_DATA 0x04
|
||||
#define SIMUL_MEMORY_DMA 0x08
|
||||
|
||||
|
||||
#define SIMUL_MEMORY_DEFAULT 0
|
||||
|
||||
#define SIMUL_MEMORY_POWERPC_SPR 1
|
||||
#define SIMUL_MEMORY_POWERPC_DCR 2
|
||||
|
||||
#define SIMUL_MEMORY_ARM_CPX 1
|
||||
|
||||
#define SIMUL_MEMORY_SH_INTACK 255
|
||||
#define SIMUL_MEMORY_M68K_INTACK 255
|
||||
|
||||
|
||||
extern int SIMULAPI SIMUL_ReadMemory(simulProcessor processor, int bustype, simulWord * paddress, int width, int cycletype, simulWord * pdata);
|
||||
|
||||
extern int SIMULAPI SIMUL_WriteMemory(simulProcessor processor, int bustype, simulWord * paddress, int width, int cycletype, simulWord * pdata);
|
||||
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterBusReadCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv, int bustype, simulWord * paddressFrom, simulWord * paddressTo);
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterBusWriteCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv, int bustype, simulWord * paddressFrom, simulWord * paddressTo);
|
||||
|
||||
extern void SIMULAPI SIMUL_RelocateBusCallback(simulProcessor processor, void * callbackid, int bustype, simulWord * paddressFrom, simulWord * paddressTo);
|
||||
|
||||
|
||||
extern void SIMULAPI SIMUL_InsertWord(simulProcessor processor, simulWord * ptarget, int wordwidth, simulWord * paddress, int width, simulWord * pdata);
|
||||
|
||||
extern void SIMULAPI SIMUL_ExtractWord(simulProcessor processor, simulWord * psource, int wordwidth, simulWord * paddress, int width, simulWord * pdata);
|
||||
|
||||
|
||||
extern void SIMULAPI SIMUL_SaveWord(simulProcessor processor, void * ptarget, int width, simulWord * pdata);
|
||||
|
||||
extern void SIMULAPI SIMUL_LoadWord(simulProcessor processor, void * psource, int width, simulWord * pdata);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Ports
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
/* predefined core ports */
|
||||
|
||||
#define SIMUL_PORT_RESET -1
|
||||
#define SIMUL_PORT_INTERRUPT -2
|
||||
|
||||
#define SIMUL_PORT_PPC_INT -2
|
||||
|
||||
#define SIMUL_PORT_ARM_IRQ -2
|
||||
#define SIMUL_PORT_ARM_FIQ -3
|
||||
|
||||
#define SIMUL_PORT_SH_IRL0 -2
|
||||
#define SIMUL_PORT_SH_IRL1 -3
|
||||
#define SIMUL_PORT_SH_IRL2 -4
|
||||
#define SIMUL_PORT_SH_IRL3 -5
|
||||
|
||||
#define SIMUL_PORT_MIPS_NMI -2
|
||||
#define SIMUL_PORT_MIPS_INT0 -3
|
||||
#define SIMUL_PORT_MIPS_INT1 -4
|
||||
#define SIMUL_PORT_MIPS_INT2 -5
|
||||
#define SIMUL_PORT_MIPS_INT3 -6
|
||||
#define SIMUL_PORT_MIPS_INT4 -7
|
||||
#define SIMUL_PORT_MIPS_INT5 -8
|
||||
|
||||
#define SIMUL_PORT_M68K_IRL0 -2
|
||||
#define SIMUL_PORT_M68K_IRL1 -3
|
||||
#define SIMUL_PORT_M68K_IRL2 -4
|
||||
|
||||
#define SIMUL_PORT_C166_IRL0 -2
|
||||
#define SIMUL_PORT_C166_IRL1 -3
|
||||
#define SIMUL_PORT_C166_IRL2 -4
|
||||
#define SIMUL_PORT_C166_IRL3 -5
|
||||
#define SIMUL_PORT_C166_NMI -6
|
||||
|
||||
/* return values for port callback functions */
|
||||
|
||||
#define SIMUL_PORT_OK 1
|
||||
|
||||
|
||||
extern int SIMULAPI SIMUL_GetPort(simulProcessor processor, int offset, int width, simulWord * pdata);
|
||||
|
||||
extern int SIMULAPI SIMUL_SetPort(simulProcessor processor, int offset, int width, simulWord * pdata);
|
||||
|
||||
extern void * SIMULAPI SIMUL_RegisterPortChangeCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv, int offset, int width);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Shared Resources
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
extern int SIMULAPI SIMUL_CreateSharedResource(simulProcessor processor, int size);
|
||||
|
||||
extern int SIMULAPI SIMUL_ReadSharedResource(simulProcessor processor, int offset, int len, void * pdata);
|
||||
|
||||
extern int SIMULAPI SIMUL_WriteSharedResource(simulProcessor processor, int offset, int len, void * pdata);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
File I/O
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
/* file modes */
|
||||
|
||||
#define SIMUL_FILE_READ 0x001
|
||||
#define SIMUL_FILE_WRITE 0x002
|
||||
#define SIMUL_FILE_CREATE 0x010
|
||||
#define SIMUL_FILE_APPEND 0x020
|
||||
#define SIMUL_FILE_BINARY 0x000
|
||||
#define SIMUL_FILE_ASCII 0x100
|
||||
|
||||
extern void * SIMULAPI SIMUL_OpenFile(simulProcessor processor, const char * filename, int mode);
|
||||
|
||||
extern void SIMULAPI SIMUL_CloseFile(simulProcessor processor, void * file);
|
||||
|
||||
extern int SIMULAPI SIMUL_ReadFile(simulProcessor processor, void * file, void * pdata, int length);
|
||||
|
||||
extern int SIMULAPI SIMUL_WriteFile(simulProcessor processor, void * file, void * pdata, int length);
|
||||
|
||||
extern int SIMULAPI SIMUL_ReadlineFile(simulProcessor processor, void * file, void * pdata, int length);
|
||||
|
||||
extern int SIMULAPI SIMUL_WritelineFile(simulProcessor processor, void * file, void * pdata);
|
||||
|
||||
#define SIMUL_FILE_SEEKABS 0
|
||||
#define SIMUL_FILE_SEEKREL 1
|
||||
#define SIMUL_FILE_SEEKEND 2
|
||||
|
||||
extern long SIMULAPI SIMUL_SeekFile(simulProcessor processor, void * file, long pos, int mode);
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
Terminal I/O
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
/* status bits */
|
||||
|
||||
#define SIMUL_STATE_RXREADY 0x001
|
||||
#define SIMUL_STATE_TXREADY 0x002
|
||||
#define SIMUL_STATE_NOTEXISTING 0x010
|
||||
|
||||
extern int SIMULAPI SIMUL_ReadTerminal(simulProcessor processor, int id);
|
||||
|
||||
extern int SIMULAPI SIMUL_WriteTerminal(simulProcessor processor, int id, int ch);
|
||||
|
||||
extern int SIMULAPI SIMUL_StateTerminal(simulProcessor processor, int id);
|
||||
|
||||
extern void * SIMUL_RegisterTerminalCallback(simulProcessor processor, simulCallbackFunctionPtr func, simulPtr priv, int id);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
End of Include
|
||||
|
||||
**************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user