/* *********************************************************************** * * CUSTOM API Declaration * * $Id: t32custom.h 87417 2017-08-08 09:45:28Z hlohn $ * $Revision: 87417 $ * * * * (c) Lauterbach GmbH * http://www.lauterbach.com/ * *********************************************************************** */ #ifndef CUSTOM_H #define CUSTOM_H /************************************************************************** Basic types and includes **************************************************************************/ #include #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 CUSTOMAPI __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(__i386__) # define CUSTOMAPI __attribute__((cdecl)) # else # define CUSTOMAPI # endif #endif #define CUSTOM_VERSION 2 #define CUSTOM_OK +1 #define CUSTOM_FAIL -1 typedef uint64_t customWord; typedef void *customContext; typedef void *customPtr; /************************************************************************** Parameter structures **************************************************************************/ #define CUSTOM_CALLBACK_INIT 0x0001 #define CUSTOM_CALLBACK_EXIT 0x0002 #define CUSTOM_CALLBACK_COMMAND 0x0004 #define CUSTOM_CALLBACK_SYSMODE 0x0008 #define CUSTOM_CALLBACK_MEMORYREAD 0x0010 #define CUSTOM_CALLBACK_MEMORYWRITE 0x0020 #define CUSTOM_CALLBACK_REGISTERREAD 0x0040 #define CUSTOM_CALLBACK_REGISTERWRITE 0x0080 #define CUSTOM_CALLBACK_STEP 0x0100 #define CUSTOM_CALLBACK_GO 0x0200 #define CUSTOM_CALLBACK_BREAK 0x0400 #define CUSTOM_CALLBACK_DISASSEMBLER 0x1000 #define CUSTOM_CALLBACK_GETSTATE 0x2000 #define CUSTOM_CALLBACK_BREAKPOINT 0x4000 typedef struct { char *commandline; /* Everything after "SYStem.LOAD" as a single string (without leading whitespace). */ int argc; /* Number of elements in the argument list passed with "SYStem.LOAD" */ char **argp; /* The argument list: Elements as string (without enclosing quotes) */ int64_t *argpInt; /* The argument list: Elements as integer (zero if argument is a string) */ customWord *argpAddress; /* The argument list: Elements as target address (zero if argument is a string) */ customWord *argpAddressUpper; /* The argument list: Uppper address of and element containing a range (argpAddressUpper[i] equals to argpAddress[i] if element is not a range) */ } customInitCallbackStruct; typedef struct { char *command; /* Name of the passed command */ char *commandline; /* Everything after "SYStem.COMMAND" as a single string (without leading whitespace). */ int argc; /* Number of elements in the argument list passed with "SYStem.COMMAND" */ char **argp; /* The argument list: Elements as string (without enclosing quotes) */ int64_t *argpInt; /* The argument list: Elements as integer (zero if argument is a string) */ customWord *argpAddress; /* The argument list: Elements as target address (zero if argument is a string) */ customWord *argpAddressUpper; /* The argument list: Uppper address of and element containing a range (argpAddressUpper[i] equals to argpAddress[i] if element is not a range) */ int *argpAddressId; /* The argument list: Id of the memory class of an addresses for "SYStem.COMMAND" (CUSTOM_MEMORY_UNREGISTERED if argument is not an address) */ } customCmdCallbackStruct; typedef struct { int idx; /* index of register to which should be written */ int core; /* index of the active processor thread/context (for SMP systems) */ customWord *data; /* content of the register set OR data which should be written to a register */ } customRegisterCallbackStruct; typedef struct { int core; /* index of the active processor thread/context (for SMP systems) */ int id; /* Id of the registered memory class to which should be written or from which should be read */ customWord address; /* byte address of the target memory location */ int length; /* amount of data to write in bytes */ int width; /* data width in which the user (or TRACE32) is accessing the memory */ uint8_t *data; /* buffer holding the data which should be written / buffer to which the read data should be copied */ } customMemoryCallbackStruct; #define CUSTOM_MEMORY_UNREGISTERED -1 typedef struct { customWord address; int flags; const uint8_t *data; char *mnemo; char *comment; int instlen; int jumpflag; customWord jumptarget; } customDisassemblerCallbackStruct; #define CUSTOM_JMPFLG_DIRECT 0x0001 #define CUSTOM_JMPFLG_DIRECTCOND 0x0002 #define CUSTOM_JMPFLG_INDIRECT 0x0004 #define CUSTOM_JMPFLG_INDIRECTCOND 0x0008 typedef struct { int mode; } customSystemModeStruct; #define CUSTOM_SYSMODE_DOWN 1 #define CUSTOM_SYSMODE_NODEBUG 2 #define CUSTOM_SYSMODE_ATTACH 4 #define CUSTOM_SYSMODE_UP 8 typedef struct { int state; char *text; int core; int bpid; } customGetstateCallbackStruct; #define CUSTOM_STATE_NOPOWER -2 #define CUSTOM_STATE_NOACCESS -1 #define CUSTOM_STATE_STOPPED 0 #define CUSTOM_STATE_RUNNING 1 #define CUSTOM_STATE_IDLE 2 #define CUSTOM_BPID_NONE -1 #define CUSTOM_BPID_SW -2 typedef struct { customWord address; customWord addressto; int addressID; customWord data; customWord datamask; int bptype; int bpid; int action; } customBreakpointCallbackStruct; #define CUSTOM_BPACTION_SET 0x01 #define CUSTOM_BPACTION_CLEAR 0x02 #define CUSTOM_BPTYPE_PROGRAM 0x01 #define CUSTOM_BPTYPE_READ 0x02 #define CUSTOM_BPTYPE_WRITE 0x04 #define CUSTOM_BPTYPE_READWRITE 0x08 #define CUSTOM_BPTYPE_READDATA 0x12 #define CUSTOM_BPTYPE_WRITEDATA 0x14 #define CUSTOM_BPTYPE_READWRITEDATA 0x18 #define CUSTOM_BPTYPE_ONTHEFLY 0x100 typedef struct customCallbackStruct_s { int type; union { customInitCallbackStruct init; /* CUSTOM_CALLBACK_INIT */ customCmdCallbackStruct command; /* CUSTOM_CALLBACK_COMMAND */ customRegisterCallbackStruct reg; /* CUSTOM_CALLBACK_REGISTERREAD / CUSTOM_CALLBACK_REGISTERWRITE */ customMemoryCallbackStruct memory; /* CUSTOM_CALLBACK_MEMORYREAD / CUSTOM_CALLBACK_MEMORYWRITE */ customDisassemblerCallbackStruct dis; /* CUSTOM_CALLBACK_DISASSEMBLER */ customSystemModeStruct system; /* CUSTOM_CALLBACK_SYSMODE */ customGetstateCallbackStruct state; /* CUSTOM_CALLBACK_GETSTATE */ customBreakpointCallbackStruct breakpoint; /* CUSTOM_CALLBACK_BREAKPOINT */ } x; } customCallbackStruct; /************************************************************************** Internal callback structure (DO NOT ACCESS THIS STRUCTURE) **************************************************************************/ typedef int (CUSTOMAPI * customCallbackFunctionPtr)(customContext context, customCallbackStruct *, customPtr proprietary); typedef struct customInfo_s { int version; void (CUSTOMAPI *printf) (customContext context, const char * format, va_list list) ATTRIBUTE_PRINTF(2, 0); void (CUSTOMAPI *warning) (customContext context, const char * format, va_list list) ATTRIBUTE_PRINTF(2, 0); int (CUSTOMAPI *executeCommand) (customContext context, char * cmdline); int (CUSTOMAPI *evaluateFunction)(customContext context, char *function, uint64_t *result_int, char *result_str, int size_str); void (CUSTOMAPI *unused5)(void); void (CUSTOMAPI *defineLibName) (customContext context, const char * name, int version); void (CUSTOMAPI *defineEndianess) (customContext context, int endianess); void (CUSTOMAPI *defineCores) (customContext context, int cores); void (CUSTOMAPI *defineMemory) (customContext context, int id, const char * name, int width, int flags); void (CUSTOMAPI *defineRegister) (customContext context, int id, const char * name, int width, int flags, customWord resetvalue); void (CUSTOMAPI *definePerfile) (customContext context, int id, const char * filename); void (CUSTOMAPI *defineSoftbreak) (customContext context, int width, const uint8_t * data); void (CUSTOMAPI *unused4)(void); void (CUSTOMAPI *unused3)(void); void (CUSTOMAPI *unused2)(void); void (CUSTOMAPI *unused1)(void); void * (CUSTOMAPI *registerGetStateCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerExitCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerCommandCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerSystemModeCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int modes); void * (CUSTOMAPI *registerStepCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerGoCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerBreakCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerReadMemoryCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerWriteMemoryCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerReadRegisterCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerWriteRegisterCallback)(customContext context, customCallbackFunctionPtr func, customPtr proprietary); void * (CUSTOMAPI *registerDisassemblerCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int mininstlen, int maxinstlen); void * (CUSTOMAPI *registerBreakpointCallback) (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int bptypes); } customInfo; #ifdef __cplusplus extern "C" { #endif /************************************************************************** Entry point **************************************************************************/ extern int CUSTOMAPI CUSTOM_Init(customContext context, customCallbackStruct * cbs); /************************************************************************** TRACE32 functions **************************************************************************/ extern int CUSTOMAPI CUSTOM_ExecuteCommand(customContext context, char * cmdline); /* Execute TRACE32 command */ extern int CUSTOMAPI CUSTOM_EvalutateFunction(customContext context, char *function, uint64_t *result_int, char *result_str, int size_str); /* Evalutate the PRATICE expression where 'function' points to and stores the result in 'result_str' and result_int' (if they pointers are not zero) */ extern void CUSTOMAPI CUSTOM_Printf (customContext context, const char * format, ...) ATTRIBUTE_PRINTF(2, 3); /* Print message line in TRACE32. (A Line Feed & Carriage Return will be added regardless of ends with '\n' or not) */ extern void CUSTOMAPI CUSTOM_Warning(customContext context, const char * format, ...) ATTRIBUTE_PRINTF(2, 3); /* Display warning in TRACE32. (A Line Feed & Carriage Return will be added regardless of ends with '\n' or not) */ /************************************************************************** Generic configuration functions **************************************************************************/ extern void CUSTOM_DefineLibName(customContext context, const char * name, int version); /* Set name and version of the project (optional) */ extern void CUSTOMAPI CUSTOM_DefineEndianess(customContext context, int endianess); #define CUSTOM_ENDIANNESS_LITTLE 0 #define CUSTOM_ENDIANNESS_BIG 1 #define CUSTOM_ENDIANESS_LITTLE CUSTOM_ENDIANNESS_LITTLE #define CUSTOM_ENDIANESS_BIG CUSTOM_ENDIANNESS_BIG extern void CUSTOMAPI CUSTOM_DefineCores(customContext context, int cores); extern void CUSTOMAPI CUSTOM_DefineMemory(customContext context, int id, const char * name, int width, int flags); #define CUSTOM_MEMORY_BYTE 1 #define CUSTOM_MEMORY_WORD 2 #define CUSTOM_MEMORY_LONG 4 #define CUSTOM_MEMORY_QUAD 8 #define CUSTOM_MEMORY_DEFAULT 0 extern void CUSTOMAPI CUSTOM_DefineRegister(customContext context, int idx, const char * name, int width, int flags, customWord resetvalue); #define CUSTOM_REGISTER_FLAGS_DEFAULT 0 #define CUSTOM_REGISTER_FLAGS_PC 1 #define CUSTOM_REGISTER_FLAGS_SP 2 #define CUSTOM_REGISTER_MAX 127 extern void CUSTOMAPI CUSTOM_DefinePerfile(customContext context, int id, const char * filename); #define CUSTOM_PERFILE_PERIPHERAHL 0 #define CUSTOM_PERFILE_REGISTER 1 extern void CUSTOMAPI CUSTOM_DefineSoftbreak(customContext context, int width, const uint8_t * data); /************************************************************************** Registration of debugging procedures **************************************************************************/ extern void * CUSTOMAPI CUSTOM_RegisterGetStateCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterResetCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterSystemModeCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int modes); extern void * CUSTOMAPI CUSTOM_RegisterGoCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterBreakCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterStepCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterMemoryReadCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterMemoryWriteCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterRegisterReadCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterRegisterWriteCallback(customContext context, customCallbackFunctionPtr func, customPtr proprietary); extern void * CUSTOMAPI CUSTOM_RegisterDisassemblerCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int mininstlen, int maxinstlen); extern void * CUSTOMAPI CUSTOM_RegisterBreakpointCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary, int bptypes); extern void * CUSTOMAPI CUSTOM_RegisterCommandCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); /* Register an optional CUSTOM command handler which can be called by SYStem.COMMAND */ extern void * CUSTOMAPI CUSTOM_RegisterExitCallback (customContext context, customCallbackFunctionPtr func, customPtr proprietary); /* Register function which will be executed when CUSTOM DLL or TRACE32 will be closed */ /*************************************************************************/ #ifdef __cplusplus } #endif #endif /* __CUSTOM_H */