/* *********************************************************************** * APU API Declaration * * $Id: t32apu.h 119800 2020-04-15 15:20:07Z jboch $ * $Revision: 119800 $ * * Documentation: pdf/api_apu.pdf. * * (c) Lauterbach GmbH * http://www.lauterbach.com/ * *********************************************************************** */ #ifndef APU_T32APU_H #define APU_T32APU_H /************************************************************************** Basic types and includes **************************************************************************/ #include #ifndef ATTRIBUTE_PRINTF # if defined(__GNUC__) || defined(__clang__) # define ATTRIBUTE_PRINTF(FORMATPOS,FIRSTARGPOS) __attribute__((format (__printf__, FORMATPOS, FIRSTARGPOS))) # else # define ATTRIBUTE_PRINTF(FORMATPOS,FIRSTARGPOS) # endif #endif #if defined(_MSC_VER) /* Microsoft Visual C++ ? (not MinGW) */ typedef signed char int8_t; typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned int uint32_t; typedef __int64 int64_t; typedef unsigned __int64 uint64_t; # define APUAPI __cdecl #else # ifndef INT8_MIN /* ISO C99 standard types not yet defined ? */ # define __STDC_LIMIT_MACROS 1 # define __STDC_CONSTANT_MACROS 1 # if defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__hpux) # include # else # include # endif # endif # if defined(__GNUC__) && defined(__cdecl) # define APUAPI __cdecl # else # define APUAPI # endif #endif # if APU_CREATE_SHARED_LIBRARY # if defined(T32HOST_WIN) # define APU_EXPORT __declspec(dllexport) # elif defined(T32HOST_LINUX) # define APU_EXPORT __attribute__((visibility("default"))) # else # define APU_EXPORT # endif # else # define APU_EXPORT # endif typedef uint32_t apuWord32; typedef uint64_t apuWord64; #define APU_VERSION 2 #ifdef APU_ARCHITECTURE_64BIT # define APU_ARCHITECTURE_WIDTH 8 typedef apuWord64 apuWord; #else # define APU_ARCHITECTURE_WIDTH 4 typedef apuWord32 apuWord; #endif typedef void * apuContext; typedef void * apuPtr; /************************************************************************** Callback structure **************************************************************************/ #define APU_CALLBACK_INIT 0x0001 #define APU_CALLBACK_EXIT 0x0002 #define APU_CALLBACK_COMMAND 0x0004 #define APU_CALLBACK_RESET 0x0008 #define APU_CALLBACK_MEMORYREAD 0x0010 #define APU_CALLBACK_MEMORYWRITE 0x0020 #define APU_CALLBACK_STEP 0x0100 #define APU_CALLBACK_GO 0x0200 #define APU_CALLBACK_BREAK 0x0400 #define APU_CALLBACK_DISASSEMBLER 0x1000 #define APU_CALLBACK_GETSTATE 0x2000 #define APU_CALLBACK_TRANSLATE 0x4000 #define APU_CALLBACK_BREAKPOINT 0x8000 #define APU_CALLBACK_ASSEMBLER 0x10000 #define APU_CALLBACK_STEPPING 0x20000 #define APU_PARAM_TYPE_KEYWORD 0 #define APU_PARAM_TYPE_BOOL 1 #define APU_PARAM_TYPE_INT 2 #define APU_PARAM_TYPE_INTRANGE 3 #define APU_PARAM_TYPE_ADDRESS 4 #define APU_PARAM_TYPE_ADDRESSRANGE 5 #define APU_PARAM_TYPE_STRING 6 typedef struct { int version; char * modelname; char * commandline; int argc; char ** argp; int * argpint; apuWord * argpword; apuWord32 * argpword32; apuWord64 * argpword64; apuWord * argpaddress; apuWord32 * argpaddress32; apuWord64 * argpaddress64; apuWord * argpwordupper; apuWord32 * argpwordupper32; apuWord64 * argpwordupper64; apuWord * argpaddressupper; apuWord32 * argpaddressupper32; apuWord64 * argpaddressupper64; /* values below this line are only valid if version >= 2 */ char ** argpstring; int * argptype; } apuParamCallbackStruct; typedef struct { apuWord address; int flags; int length; int width; unsigned char * data; } apuMemoryCallbackStruct; typedef struct { apuWord address; int flags; const unsigned char * data; char * mnemo; char * comment; int instlen; int jumpflag; apuWord jumptarget; #ifdef ARCH_CEVAX int jumpPredicate; int loopLength; #endif } apuDisassemblerCallbackStruct; typedef struct { apuWord address; int flags; const unsigned char * data; const apuWord * registers; int jumpflag; apuWord jumptarget; } apuSteppingCallbackStruct; #define APU_JMPFLG_DIRECT 0x0001 #define APU_JMPFLG_DIRECTCOND 0x0002 #define APU_JMPFLG_INDIRECT 0x0004 #define APU_JMPFLG_INDIRECTCOND 0x0008 typedef struct { apuWord address; int flags; int complete; const char * mnemo; unsigned char * data; int instlen; int mnemolen; char * errormessage; int errorpos; } apuAssemblerCallbackStruct; typedef struct { apuWord pc; int state; const char * text; } apuGetstateCallbackStruct; #define APU_STATE_STOPPED 0 #define APU_STATE_RUNNING 1 #define APU_STATE_IDLE 2 typedef struct { apuWord address; int flags; int direction; } apuTranslateCallbackStruct; #define APU_TRANSLATE_TO_MAINCORE 0 #define APU_TRANSLATE_TO_SUBCORE 1 typedef struct { apuWord address; apuWord addressto; int flags; int bptype; int bpid; } apuBreakpointCallbackStruct; #define APU_BPTYPE_PROGRAM 1 #define APU_BPTYPE_READ 2 #define APU_BPTYPE_WRITE 4 typedef struct { int type; union { apuParamCallbackStruct init; apuParamCallbackStruct command; apuMemoryCallbackStruct memory; apuDisassemblerCallbackStruct dis; apuSteppingCallbackStruct step; apuAssemblerCallbackStruct ass; apuGetstateCallbackStruct state; apuTranslateCallbackStruct translate; apuBreakpointCallbackStruct breakpoint; } x; } apuCallbackStruct; typedef int (APUAPI * apuCallbackFunctionPtr)(apuContext context, apuCallbackStruct *, apuPtr proprietary); /************************************************************************** Internal callback structure (DO NOT ACCESS THIS STRUCTURE) **************************************************************************/ typedef struct apuInfo_s { int version; void (APUAPI *printf) (apuContext context, const char * format, va_list list) ATTRIBUTE_PRINTF(2, 0); void (APUAPI *warning)(apuContext context, const char * format, va_list list) ATTRIBUTE_PRINTF(2, 0); void (APUAPI *unused1)(void); void (APUAPI *unused2)(void); int (APUAPI *executeCommand) (apuContext context, char * cmdline); int (APUAPI *getState) (apuContext context, int * pstate); void (APUAPI *defineEndianess) (apuContext context, int endianess); void (APUAPI *defineMemory) (apuContext context, int id, const char * name, int width, int flags); void (APUAPI *defineSoftbreak) (apuContext context, int width, const unsigned char * data); int (APUAPI *getSymbol) (apuContext context, const char * name, apuWord * paddress, int * pflags, int width); void (APUAPI *unused4)(void); void (APUAPI *unused5)(void); int (APUAPI *readMemory32) (apuContext context, apuWord32 address, int flags, unsigned char * pdata, int size, int width); int (APUAPI *readMemory64) (apuContext context, apuWord64 address, int flags, unsigned char * pdata, int size, int width); int (APUAPI *writeMemory32)(apuContext context, apuWord32 address, int flags, unsigned char * pdata, int size, int width); int (APUAPI *writeMemory64)(apuContext context, apuWord64 address, int flags, unsigned char * pdata, int size, int width); void * (APUAPI *registerGetStateCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerExitCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerCommandCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerResetCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerStepCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerGoCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerBreakCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); void * (APUAPI *registerReadMemoryCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int archWidth); void * (APUAPI *registerWriteMemoryCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int archWidth); void * (APUAPI *registerDisassemblerCallback)(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int mininstlen, int maxinstlen, int archWidth); void * (APUAPI *registerTranslateCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int archWidth); void * (APUAPI *registerBreakpointCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int bptypes, int archWidth); void * (APUAPI *registerAssemblerCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int archWidth); void * (APUAPI *registerSteppingCallback) (apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int archWidth); } apuInfo; #ifdef __cplusplus extern "C" { #endif /************************************************************************** Model entry definition **************************************************************************/ #define APU_OK 1 #define APU_FAIL -1 extern int APUAPI APU_Init(apuContext context, apuCallbackStruct * cbs); int APU_EXPORT APUAPI APU_Interface(apuContext context, apuCallbackStruct * cbs); #define APU_ENDIANNESS_LITTLE 0 #define APU_ENDIANNESS_BIG 1 #define APU_ENDIANESS_LITTLE APU_ENDIANNESS_LITTLE #define APU_ENDIANESS_BIG APU_ENDIANNESS_BIG extern void APUAPI APU_DefineEndianess(apuContext context, int endianess); extern void APUAPI APU_DefineMemory(apuContext context, int id, const char * name, int width, int flags); extern void APUAPI APU_DefineSoftbreak(apuContext context, int width, const unsigned char * data); extern int APUAPI APU_GetSymbol(apuContext context, const char * name, apuWord * paddress, int * pflags); /************************************************************************** Generic configuration functions **************************************************************************/ extern void APUAPI APU_Printf (apuContext context, const char * format, ...) ATTRIBUTE_PRINTF(2, 3); extern void APUAPI APU_Warning(apuContext context, const char * format, ...) ATTRIBUTE_PRINTF(2, 3); extern void * APUAPI APU_RegisterGetStateCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterResetCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterExitCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterCommandCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterStepCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterGoCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterBreakCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterMemoryReadCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterMemoryWriteCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterDisassemblerCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int mininstlen, int maxinstlen); extern void * APUAPI APU_RegisterSteppingCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterAssemblerCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterTranslateCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary); extern void * APUAPI APU_RegisterBreakpointCallback(apuContext context, apuCallbackFunctionPtr func, apuPtr proprietary, int bptypes); /************************************************************************** Access to main core debugger **************************************************************************/ /* Main core meomory classes */ #define T32_MEMORY_ACCESS_DATA 0x0000 #define T32_MEMORY_ACCESS_PROGRAM 0x0001 #define T32_MEMORY_ACCESS_USR 0x000f #define T32_MEMORY_ACCESS_VM 0x0010 #define T32_MEMORY_ACCESS_ARM_CP0 0x0002 #define T32_MEMORY_ACCESS_ARM_ICE 0x0003 #define T32_MEMORY_ACCESS_ARM_ETM 0x0004 #define T32_MEMORY_ACCESS_ARM_CP14 0x0005 #define T32_MEMORY_ACCESS_ARM_CP15 0x0006 #define T32_MEMORY_ACCESS_ARM_ARM 0x0007 #define T32_MEMORY_ACCESS_ARM_THUMB 0x0008 #define T32_MEMORY_ACCESS_ARM_PHYSICAL_ARM 0x0009 #define T32_MEMORY_ACCESS_ARM_PHYSICAL_THUMB 0x000a #define T32_MEMORY_ACCESS_ARM_ETB 0x000b #define T32_MEMORY_ACCESS_ARM_PHYSICAL_DATA 0x000c #define T32_MEMORY_ACCESS_ARM_PHYSICAL_PROGRAM 0x000d #define T32_MEMORY_ACCESS_ARM_DAP 0x000e #define T32_MEMORY_ACCESS_ARM_USR T32_MEMORY_ACCESS_USR #define T32_MEMORY_ACCESS_ARM_DBG 0x0011 #define T32_MEMORY_ACCESS_ARC_AUX 0x0002 #define T32_MEMORY_ACCESS_PPC_SPR 0x0002 #define T32_MEMORY_ACCESS_PPC_DCR 0x0003 #define T32_MEMORY_ACCESS_X86_LD 0x0002 #define T32_MEMORY_ACCESS_X86_LP 0x0003 #define T32_MEMORY_ACCESS_X86_IO 0x0004 #define T32_MEMORY_ACCESS_X86_MSR 0x0005 #define T32_MEMORY_ACCESS_XTENSA_DAP T32_MEMORY_ACCESS_ARM_DAP #define T32_MEMORY_ACCESS_XTENSA_SPR 0x0002 #define T32_MEMORY_ATTR_DUALPORT 0x0400 /* Main Core memory classes -- DEPRECATED; use T32_MEMORY_* macros defined * above */ #define APU_MAINCORE_D T32_MEMORY_ACCESS_DATA #define APU_MAINCORE_P T32_MEMORY_ACCESS_PROGRAM #define APU_MAINCORE_PD T32_MEMORY_ACCESS_ARM_PHYSICAL_DATA #define APU_MAINCORE_PP T32_MEMORY_ACCESS_ARM_PHYSICAL_PROGRAM #define APU_MAINCORE_USR T32_MEMORY_ACCESS_USR #define APU_MAINCORE_E 0x80000000 extern int APUAPI APU_GetState(apuContext context, int * pstate); extern int APUAPI APU_ReadMemory(apuContext context, apuWord address, int flags, unsigned char * pdata, int size, int width); extern int APUAPI APU_WriteMemory(apuContext context, apuWord address, int flags, unsigned char * pdata, int size, int width); extern int APUAPI APU_ExecuteCommand(apuContext context, char * cmdline); /************************************************************************** End of Include **************************************************************************/ #ifdef __cplusplus } #endif #endif /* #ifdef APU_T32APU_H */